@ -16,6 +16,7 @@ package crypto
import (
import (
"net/http"
"net/http"
"sort"
"testing"
"testing"
)
)
@ -337,3 +338,102 @@ func TestSSECopyParse(t *testing.T) {
}
}
}
}
}
}
var removeSensitiveHeadersTests = [ ] struct {
Header , ExpectedHeader http . Header
} {
{
Header : http . Header {
SSECKey : [ ] string { "" } ,
SSECopyKey : [ ] string { "" } ,
} ,
ExpectedHeader : http . Header { } ,
} ,
{ // Standard SSE-C request headers
Header : http . Header {
SSECAlgorithm : [ ] string { SSEAlgorithmAES256 } ,
SSECKey : [ ] string { "MzJieXRlc2xvbmdzZWNyZXRrZXltdXN0cHJvdmlkZWQ=" } ,
SSECKeyMD5 : [ ] string { "7PpPLAK26ONlVUGOWlusfg==" } ,
} ,
ExpectedHeader : http . Header {
SSECAlgorithm : [ ] string { SSEAlgorithmAES256 } ,
SSECKeyMD5 : [ ] string { "7PpPLAK26ONlVUGOWlusfg==" } ,
} ,
} ,
{ // Standard SSE-C + SSE-C-copy request headers
Header : http . Header {
SSECAlgorithm : [ ] string { SSEAlgorithmAES256 } ,
SSECKey : [ ] string { "MzJieXRlc2xvbmdzZWNyZXRrZXltdXN0cHJvdmlkZWQ=" } ,
SSECKeyMD5 : [ ] string { "7PpPLAK26ONlVUGOWlusfg==" } ,
SSECopyKey : [ ] string { "MzJieXRlc2xvbmdzZWNyZXRrZXltdXN0cHJvdmlkZWQ=" } ,
SSECopyKeyMD5 : [ ] string { "7PpPLAK26ONlVUGOWlusfg==" } ,
} ,
ExpectedHeader : http . Header {
SSECAlgorithm : [ ] string { SSEAlgorithmAES256 } ,
SSECKeyMD5 : [ ] string { "7PpPLAK26ONlVUGOWlusfg==" } ,
SSECopyKeyMD5 : [ ] string { "7PpPLAK26ONlVUGOWlusfg==" } ,
} ,
} ,
{ // Standard SSE-C + metadata request headers
Header : http . Header {
SSECAlgorithm : [ ] string { SSEAlgorithmAES256 } ,
SSECKey : [ ] string { "MzJieXRlc2xvbmdzZWNyZXRrZXltdXN0cHJvdmlkZWQ=" } ,
SSECKeyMD5 : [ ] string { "7PpPLAK26ONlVUGOWlusfg==" } ,
"X-Amz-Meta-Test-1" : [ ] string { "Test-1" } ,
} ,
ExpectedHeader : http . Header {
SSECAlgorithm : [ ] string { SSEAlgorithmAES256 } ,
SSECKeyMD5 : [ ] string { "7PpPLAK26ONlVUGOWlusfg==" } ,
"X-Amz-Meta-Test-1" : [ ] string { "Test-1" } ,
} ,
} ,
}
func TestRemoveSensitiveHeaders ( t * testing . T ) {
isEqual := func ( x , y http . Header ) bool {
if len ( x ) != len ( y ) {
return false
}
for k , v := range x {
u , ok := y [ k ]
if ! ok || len ( v ) != len ( u ) {
return false
}
sort . Strings ( v )
sort . Strings ( u )
for j := range v {
if v [ j ] != u [ j ] {
return false
}
}
}
return true
}
areKeysEqual := func ( h http . Header , metadata map [ string ] string ) bool {
if len ( h ) != len ( metadata ) {
return false
}
for k := range h {
if _ , ok := metadata [ k ] ; ! ok {
return false
}
}
return true
}
for i , test := range removeSensitiveHeadersTests {
metadata := make ( map [ string ] string , len ( test . Header ) )
for k := range test . Header {
metadata [ k ] = "" // set metadata key - we don't care about the value
}
RemoveSensitiveHeaders ( test . Header )
if ! isEqual ( test . ExpectedHeader , test . Header ) {
t . Errorf ( "Test %d: filtered headers do not match expected headers - got: %v , want: %v" , i , test . Header , test . ExpectedHeader )
}
RemoveSensitiveEntries ( metadata )
if ! areKeysEqual ( test . ExpectedHeader , metadata ) {
t . Errorf ( "Test %d: filtered headers do not match expected headers - got: %v , want: %v" , i , test . Header , test . ExpectedHeader )
}
}
}