2015-05-15 23:50:17 +00:00
|
|
|
package transport
|
2015-05-07 20:16:52 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestAuthChallengeParse(t *testing.T) {
|
|
|
|
header := http.Header{}
|
|
|
|
header.Add("WWW-Authenticate", `Bearer realm="https://auth.example.com/token",service="registry.example.com",other=fun,slashed="he\"\l\lo"`)
|
|
|
|
|
|
|
|
challenges := parseAuthHeader(header)
|
|
|
|
if len(challenges) != 1 {
|
|
|
|
t.Fatalf("Unexpected number of auth challenges: %d, expected 1", len(challenges))
|
|
|
|
}
|
2015-05-11 18:31:22 +00:00
|
|
|
challenge := challenges["bearer"]
|
2015-05-07 20:16:52 +00:00
|
|
|
|
2015-05-11 18:31:22 +00:00
|
|
|
if expected := "bearer"; challenge.Scheme != expected {
|
|
|
|
t.Fatalf("Unexpected scheme: %s, expected: %s", challenge.Scheme, expected)
|
2015-05-07 20:16:52 +00:00
|
|
|
}
|
|
|
|
|
2015-05-11 18:31:22 +00:00
|
|
|
if expected := "https://auth.example.com/token"; challenge.Parameters["realm"] != expected {
|
|
|
|
t.Fatalf("Unexpected param: %s, expected: %s", challenge.Parameters["realm"], expected)
|
2015-05-07 20:16:52 +00:00
|
|
|
}
|
|
|
|
|
2015-05-11 18:31:22 +00:00
|
|
|
if expected := "registry.example.com"; challenge.Parameters["service"] != expected {
|
|
|
|
t.Fatalf("Unexpected param: %s, expected: %s", challenge.Parameters["service"], expected)
|
2015-05-07 20:16:52 +00:00
|
|
|
}
|
|
|
|
|
2015-05-11 18:31:22 +00:00
|
|
|
if expected := "fun"; challenge.Parameters["other"] != expected {
|
|
|
|
t.Fatalf("Unexpected param: %s, expected: %s", challenge.Parameters["other"], expected)
|
2015-05-07 20:16:52 +00:00
|
|
|
}
|
|
|
|
|
2015-05-11 18:31:22 +00:00
|
|
|
if expected := "he\"llo"; challenge.Parameters["slashed"] != expected {
|
|
|
|
t.Fatalf("Unexpected param: %s, expected: %s", challenge.Parameters["slashed"], expected)
|
2015-05-07 20:16:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|