Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle proprietary headers in spec summary. #57

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ go 1.15

require (
github.com/OneOfOne/xxhash v1.2.8
github.com/akitasoftware/akita-ir v0.0.0-20210211235551-a548c32e7fbe
github.com/akitasoftware/akita-ir v0.0.0-20210709202958-12143082fbe1
github.com/akitasoftware/objecthash-proto v0.0.0-20200508002052-e5b6b45fd2ba
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883
github.com/benlaurie/objecthash v0.0.0-20180202135721-d1e3d6079fc1 // indirect
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b
// Golang protobuf APIv1, needed to compatibility with objecthash-proto. See
// pb/README.md
Expand Down
21 changes: 7 additions & 14 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,18 @@ github.com/OneOfOne/xxhash v1.2.8 h1:31czK/TI9sNkxIKfaUfGlU47BAxQ0ztGgd9vPyqimf8
github.com/OneOfOne/xxhash v1.2.8/go.mod h1:eZbhyaAYD41SGSSsnmcpxVoRiQ/MPUTjUdIIOT9Um7Q=
github.com/akitasoftware/akita-ir v0.0.0-20210211235551-a548c32e7fbe h1:2oL/uTiN0aSaN3M9yrYZeZKr2p3YUgkCYVYuMhoaIDk=
github.com/akitasoftware/akita-ir v0.0.0-20210211235551-a548c32e7fbe/go.mod h1:WEWPzhZtxlJnov3MxcqSDiZaHHf00vs3aJwCdt3OwzA=
github.com/akitasoftware/akita-ir v0.0.0-20210709202958-12143082fbe1 h1:Wi4xcN3L3JCLnpJtN5UPAgz9QoO+UP/l3pD73owWPNg=
github.com/akitasoftware/akita-ir v0.0.0-20210709202958-12143082fbe1/go.mod h1:igaEQaqD4O1y+bNiy5ASPqnzCcxC9HLzPapT7VEhzgs=
github.com/akitasoftware/gopacket v1.1.18-0.20201119235945-f584f5125293 h1:lrR1zarKR584gABHjW4Kd7ZQTb3h1LHJXYAUo5wh6do=
github.com/akitasoftware/gopacket v1.1.18-0.20201119235945-f584f5125293/go.mod h1:MBrCPyoWRP/pI7XvrdNAVmh6l3jHcGbIhYmF4J6xPrk=
github.com/akitasoftware/martian/v3 v3.0.1-0.20210108221002-22c39e10ccd2 h1:sBPBv9mohlLY3EzstN6ds8kxcc0lwq1F541115FP7xY=
github.com/akitasoftware/martian/v3 v3.0.1-0.20210108221002-22c39e10ccd2/go.mod h1:qDTWoRR9LvzAsPM1JYaThR7tyE63cEy3XPkox/4pP1A=
github.com/akitasoftware/martian/v3 v3.0.1-0.20210408175823-8159a63604a0 h1:I6dMrqlMXbXKpCQUCXKif6eT2FbG9GiXtGTUgBAJHlQ=
github.com/akitasoftware/martian/v3 v3.0.1-0.20210408175823-8159a63604a0/go.mod h1:qDTWoRR9LvzAsPM1JYaThR7tyE63cEy3XPkox/4pP1A=
github.com/akitasoftware/martian/v3 v3.0.1-0.20210607215513-d8717bec3637 h1:RsGofPPzDUAg+iYDd+N8l+YFhWSihp6ca0rW8bP7MPw=
github.com/akitasoftware/martian/v3 v3.0.1-0.20210607215513-d8717bec3637/go.mod h1:qDTWoRR9LvzAsPM1JYaThR7tyE63cEy3XPkox/4pP1A=
github.com/akitasoftware/martian/v3 v3.0.1-0.20210607230525-1acfb608de0d h1:G4DBVe2XdmNQWgzWI2M5pycWVJE9nRrGJz9/csxai34=
github.com/akitasoftware/martian/v3 v3.0.1-0.20210607230525-1acfb608de0d/go.mod h1:qDTWoRR9LvzAsPM1JYaThR7tyE63cEy3XPkox/4pP1A=
github.com/akitasoftware/martian/v3 v3.0.1-0.20210608174341-829c1134e9de h1:rWkji88f/EWUY+qGc6pEyhpjgFbpsXwrnlTDTu5mLjY=
github.com/akitasoftware/martian/v3 v3.0.1-0.20210608174341-829c1134e9de/go.mod h1:qDTWoRR9LvzAsPM1JYaThR7tyE63cEy3XPkox/4pP1A=
github.com/akitasoftware/objecthash-proto v0.0.0-20200508002052-e5b6b45fd2ba h1:sAv1pLJk8VU9q8CddBocaftsZnb2ppbBEQSN6H5O3kg=
github.com/akitasoftware/objecthash-proto v0.0.0-20200508002052-e5b6b45fd2ba/go.mod h1:otNn0Cq1YGR1daOez6qwaCaF9tzRk1YkIsxF+6faKNE=
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883 h1:bvNMNQO63//z+xNgfBlViaCIJKLlCJ6/fmUseuG0wVQ=
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/benlaurie/objecthash v0.0.0-20180202135721-d1e3d6079fc1 h1:VRtJdDi2lqc3MFwmouppm2jlm6icF+7H3WYKpLENMTo=
github.com/benlaurie/objecthash v0.0.0-20180202135721-d1e3d6079fc1/go.mod h1:jvdWlw8vowVGnZqSDC7yhPd7AifQeQbRDkZcQXV2nRg=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand All @@ -28,15 +23,12 @@ github.com/golang/protobuf v1.3.4 h1:87PNWwrRvUSnqS4dlcBU/ftvOIBep4sYuBLlh6rX2wk
github.com/golang/protobuf v1.3.4/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
github.com/google/go-cmp v0.5.4 h1:L8R9j+yAqZuZjsqh/z+F1NCffTKKLShY6zXTItVIZ8M=
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/gopacket v1.1.19 h1:ves8RnFZPGiFnTS0uPQStjwru6uO6h+nlr9j6fL7kF8=
github.com/google/gopacket v1.1.19/go.mod h1:iJ8V8n6KS+z2U1A8pUwu8bW5SyEMkXJB8Yo/Vo+TKTo=
github.com/google/martian v2.1.0+incompatible h1:/CP5g8u/VJHijgedC/Legn3BAbAaWPgecwXBIDzw5no=
github.com/google/martian/v3 v3.1.0 h1:wCKgOCHuUEVfsaQLpPSJb7VdYCdTVZQAuOdYm1yc/60=
github.com/google/martian/v3 v3.1.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0=
github.com/google/uuid v1.2.0 h1:qJYtXnJRWmpe7m/3XlyhrsLrEURqHRM2kxzoxXqyUDs=
github.com/google/uuid v1.2.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
Expand Down Expand Up @@ -64,6 +56,7 @@ golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8T
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
Expand Down
9 changes: 8 additions & 1 deletion spec_summary/summarize.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,14 @@ func (v *specSummaryVisitor) LeaveMethod(self interface{}, _ vis.SpecVisitorCont
func (v *specSummaryVisitor) LeaveData(self interface{}, _ vis.SpecVisitorContext, d *pb.Data, cont Cont) Cont {
// Handle auth vs params vs properties.
if meta := spec_util.HTTPAuthFromData(d); meta != nil {
v.methodSummary.Authentications[meta.Type.String()] += 1
// For proprietary headers, use the header value, otherwise
// use the type.
switch meta.Type {
case pb.HTTPAuth_PROPRIETARY_HEADER:
v.methodSummary.Authentications[meta.ProprietaryHeader] += 1
default:
v.methodSummary.Authentications[meta.Type.String()] += 1
}
} else if meta := spec_util.HTTPPathFromData(d); meta != nil {
v.methodSummary.Params[meta.Key] += 1
} else if meta := spec_util.HTTPQueryFromData(d); meta != nil {
Expand Down
97 changes: 68 additions & 29 deletions spec_summary/summarize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,77 @@ import (
)

func TestSummarize(t *testing.T) {
expected := &Summary{
Authentications: map[string]int{
"BASIC": 1,
testCases := []struct {
File string
Expected *Summary
}{
{
"testdata/method1.pb.txt",
&Summary{
Authentications: map[string]int{
"BASIC": 1,
},
HTTPMethods: map[string]int{
"POST": 1,
},
Paths: map[string]int{
"/v1/projects/{arg3}": 1,
},
Params: map[string]int{
"X-My-Header": 1,
},
Properties: map[string]int{
"top-level-prop": 1,
"my-special-prop": 1,
"other-top-level-prop": 1,
},
ResponseCodes: map[string]int{
"200": 1,
},
DataFormats: map[string]int{
"rfc3339": 1,
},
DataKinds: map[string]int{},
DataTypes: map[string]int{
"string": 1,
},
},
},
HTTPMethods: map[string]int{
"POST": 1,
},
Paths: map[string]int{
"/v1/projects/{arg3}": 1,
},
Params: map[string]int{
"X-My-Header": 1,
},
Properties: map[string]int{
"top-level-prop": 1,
"my-special-prop": 1,
"other-top-level-prop": 1,
},
ResponseCodes: map[string]int{
"200": 1,
},
DataFormats: map[string]int{
"rfc3339": 1,
},
DataKinds: map[string]int{},
DataTypes: map[string]int{
"string": 1,
{
"testdata/method2.pb.txt",
&Summary{
Authentications: map[string]int{
"NTLM": 1,
"X-Hub-Signature-256": 1,
},
HTTPMethods: map[string]int{
"GET": 1,
},
Paths: map[string]int{
"/v1/projects/{arg3}": 1,
},
ResponseCodes: map[string]int{
"404": 1,
},
Properties: map[string]int{
"message": 1,
},
DataTypes: map[string]int{
"string": 1,
},
// Expected to be empty but not nil
Params: map[string]int{},
DataFormats: map[string]int{},
DataKinds: map[string]int{},
},
},
}

m1 := test.LoadMethodFromFileOrDie("testdata/method1.pb.txt")
assert.Equal(t, expected, Summarize(&pb.APISpec{Methods: []*pb.Method{m1}}))
for _, tc := range testCases {
t.Logf("Test case: %q", tc.File)
m1 := test.LoadMethodFromFileOrDie(tc.File)
assert.Equal(t, tc.Expected, Summarize(&pb.APISpec{Methods: []*pb.Method{m1}}))
}
}

func TestIntersect(t *testing.T) {
Expand All @@ -68,4 +107,4 @@ func TestIntersect(t *testing.T) {
assert.Equal(t, setM2, intersect([]map[*pb.Method]struct{}{setM2, setM12}))
assert.Equal(t, setM2, intersect([]map[*pb.Method]struct{}{setM12, setM2}))
assert.Equal(t, setM12, intersect([]map[*pb.Method]struct{}{setM12, setM12}))
}
}
63 changes: 63 additions & 0 deletions spec_summary/testdata/method2.pb.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# pb.Method proto

args: {
key: "auth-arg"
value: {
meta: {
http: {
auth: {
type: NTLM
}
}
}
}
}

args: {
key: "auth-arg-2"
value: {
meta: {
http: {
auth: {
type: PROPRIETARY_HEADER
proprietary_header: "X-Hub-Signature-256"
}
}
}
}
}

responses: {
key: "body-resp"
value: {
struct: {
fields: {
key: "message"
value: {
primitive: {
string_value: {
type: {}
}
}
}
}
}

meta: {
http: {
body: {
content_type: JSON
}
response_code: 404
}
}
}
}

meta: {
http: {
method: "GET"
path_template: "/v1/projects/{arg3}"
host: "example.com"
}
}