@@ -57,6 +57,32 @@ func TestAuthHandler(t *testing.T) {
57
57
assert .Equal (t , "content" , resp .Body .String ())
58
58
}
59
59
60
+ func TestAuthHandler_WithTokenKeys (t * testing.T ) {
61
+ const key = "B63F477D-BBA3-4E52-96D3-C0034C27694A"
62
+ req := httptest .NewRequest (http .MethodGet , "http://localhost" , http .NoBody )
63
+ token , err := buildToken (key , map [string ]any {
64
+ "key" : "value" ,
65
+ }, 3600 )
66
+ assert .Nil (t , err )
67
+ req .Header .Set ("X-Token" , token )
68
+ handler := Authorize (key , WithTokenKeys ([]string {"Token" , "X-Token" }))(
69
+ http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
70
+ w .Header ().Set ("X-Test" , "test" )
71
+ _ , err := w .Write ([]byte ("content" ))
72
+ assert .Nil (t , err )
73
+
74
+ flusher , ok := w .(http.Flusher )
75
+ assert .True (t , ok )
76
+ flusher .Flush ()
77
+ }))
78
+
79
+ resp := httptest .NewRecorder ()
80
+ handler .ServeHTTP (resp , req )
81
+ assert .Equal (t , http .StatusOK , resp .Code )
82
+ assert .Equal (t , "test" , resp .Header ().Get ("X-Test" ))
83
+ assert .Equal (t , "content" , resp .Body .String ())
84
+ }
85
+
60
86
func TestAuthHandlerWithPrevSecret (t * testing.T ) {
61
87
const (
62
88
key = "14F17379-EB8F-411B-8F12-6929002DCA76"
0 commit comments