-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Add a header type field #4993
Add a header type field #4993
Changes from all commits
7b86f41
fdbb32a
7ad2511
bc18aa0
a3a7cb3
a3286a9
ef89439
d4fb65f
f0443e0
b190a4e
b1cd520
ab5a906
f486653
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
package framework | ||
|
||
import ( | ||
"net/http" | ||
"reflect" | ||
"testing" | ||
) | ||
|
@@ -467,6 +468,87 @@ func TestFieldDataGet(t *testing.T) { | |
}, | ||
}, | ||
|
||
"type header, keypair string array": { | ||
map[string]*FieldSchema{ | ||
"foo": {Type: TypeHeader}, | ||
}, | ||
map[string]interface{}{ | ||
"foo": []interface{}{"key1:value1", "key2:value2", "key3:1"}, | ||
}, | ||
"foo", | ||
http.Header{ | ||
"Key1": []string{"value1"}, | ||
"Key2": []string{"value2"}, | ||
"Key3": []string{"1"}, | ||
}, | ||
}, | ||
|
||
"type header, b64 string": { | ||
map[string]*FieldSchema{ | ||
"foo": {Type: TypeHeader}, | ||
}, | ||
map[string]interface{}{ | ||
"foo": "eyJDb250ZW50LUxlbmd0aCI6IFsiNDMiXSwgIlVzZXItQWdlbnQiOiBbImF3cy1zZGstZ28vMS40LjEyIChnbzEuNy4xOyBsaW51eDsgYW1kNjQpIl0sICJYLVZhdWx0LUFXU0lBTS1TZXJ2ZXItSWQiOiBbInZhdWx0LmV4YW1wbGUuY29tIl0sICJYLUFtei1EYXRlIjogWyIyMDE2MDkzMFQwNDMxMjFaIl0sICJDb250ZW50LVR5cGUiOiBbImFwcGxpY2F0aW9uL3gtd3d3LWZvcm0tdXJsZW5jb2RlZDsgY2hhcnNldD11dGYtOCJdLCAiQXV0aG9yaXphdGlvbiI6IFsiQVdTNC1ITUFDLVNIQTI1NiBDcmVkZW50aWFsPWZvby8yMDE2MDkzMC91cy1lYXN0LTEvc3RzL2F3czRfcmVxdWVzdCwgU2lnbmVkSGVhZGVycz1jb250ZW50LWxlbmd0aDtjb250ZW50LXR5cGU7aG9zdDt4LWFtei1kYXRlO3gtdmF1bHQtc2VydmVyLCBTaWduYXR1cmU9YTY5ZmQ3NTBhMzQ0NWM0ZTU1M2UxYjNlNzlkM2RhOTBlZWY1NDA0N2YxZWI0ZWZlOGZmYmM5YzQyOGMyNjU1YiJdfQ==", | ||
}, | ||
"foo", | ||
http.Header{ | ||
"Content-Length": []string{"43"}, | ||
"User-Agent": []string{"aws-sdk-go/1.4.12 (go1.7.1; linux; amd64)"}, | ||
"X-Vault-Awsiam-Server-Id": []string{"vault.example.com"}, | ||
"X-Amz-Date": []string{"20160930T043121Z"}, | ||
"Content-Type": []string{"application/x-www-form-urlencoded; charset=utf-8"}, | ||
"Authorization": []string{"AWS4-HMAC-SHA256 Credential=foo/20160930/us-east-1/sts/aws4_request, SignedHeaders=content-length;content-type;host;x-amz-date;x-vault-server, Signature=a69fd750a3445c4e553e1b3e79d3da90eef54047f1eb4efe8ffbc9c428c2655b"}, | ||
}, | ||
}, | ||
|
||
"type header, json string": { | ||
map[string]*FieldSchema{ | ||
"foo": {Type: TypeHeader}, | ||
}, | ||
map[string]interface{}{ | ||
"foo": `{"hello":"world","bonjour":["monde","dieu"]}`, | ||
}, | ||
"foo", | ||
http.Header{ | ||
"Hello": []string{"world"}, | ||
"Bonjour": []string{"monde", "dieu"}, | ||
}, | ||
}, | ||
|
||
"type header, keypair string array with dupe key": { | ||
map[string]*FieldSchema{ | ||
"foo": {Type: TypeHeader}, | ||
}, | ||
map[string]interface{}{ | ||
"foo": []interface{}{"key1:value1", "key2:value2", "key3:1", "key3:true"}, | ||
}, | ||
"foo", | ||
http.Header{ | ||
"Key1": []string{"value1"}, | ||
"Key2": []string{"value2"}, | ||
"Key3": []string{"1", "true"}, | ||
}, | ||
}, | ||
|
||
"type header, map string slice": { | ||
map[string]*FieldSchema{ | ||
"foo": {Type: TypeHeader}, | ||
}, | ||
map[string]interface{}{ | ||
"foo": map[string][]string{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the JSON Unmarshaller will return this as a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will do. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was a good test! I ran Vault in dev mode and made a little path that took
And it actually parsed both the faux bool and the faux int field with no error, and they came in as strings, which is what I would want for a header. |
||
"key1": {"value1"}, | ||
"key2": {"value2"}, | ||
"key3": {"1"}, | ||
}, | ||
}, | ||
"foo", | ||
http.Header{ | ||
"Key1": []string{"value1"}, | ||
"Key2": []string{"value2"}, | ||
"Key3": []string{"1"}, | ||
}, | ||
}, | ||
|
||
"name string type, not supplied": { | ||
map[string]*FieldSchema{ | ||
"foo": {Type: TypeNameString}, | ||
|
@@ -556,6 +638,15 @@ func TestFieldDataGet(t *testing.T) { | |
"foo", | ||
map[string]string{}, | ||
}, | ||
|
||
"type header, not supplied": { | ||
map[string]*FieldSchema{ | ||
"foo": {Type: TypeHeader}, | ||
}, | ||
map[string]interface{}{}, | ||
"foo", | ||
http.Header{}, | ||
}, | ||
} | ||
|
||
for name, tc := range cases { | ||
|
@@ -565,7 +656,7 @@ func TestFieldDataGet(t *testing.T) { | |
} | ||
|
||
if err := data.Validate(); err != nil { | ||
t.Fatalf("bad: %#v", err) | ||
t.Fatalf("bad: %s", err) | ||
} | ||
|
||
actual := data.Get(tc.Key) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't this need to be
range typedHeader.([]string)
? Same with the case below.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes and no. It's already converted to an []string here:
switch typedHeader := headerValGroup.(type)
. The type is used in the switch below and it's actually cast to it when it's instantiated there on the left. Went off of this.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah right, I mixed up:
which doesn't have that type with what you did here, which does. Great!