@@ -2,6 +2,7 @@ package auth
22
33import (
44 "encoding/json"
5+ "fmt"
56 "net/http"
67 "net/http/httptest"
78 "strings"
@@ -350,3 +351,34 @@ func TestAuthorizerCache_ExpiringEntry(t *testing.T) {
350351 assert .True (t , tc .assertOpts (t , opts ))
351352 }
352353}
354+ func BenchmarkCachedAuthorizer (b * testing.B ) {
355+ opts := int32 (0 )
356+
357+ svr := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
358+ atomic .AddInt32 (& opts , 1 )
359+ w .WriteHeader (http .StatusOK )
360+ _ = json .NewEncoder (w ).Encode (& TenantInfo {
361+ AuthorizedParty : fmt .Sprintf ("tester-%d" , opts ),
362+ Environment : fmt .Sprintf ("env-%d" , opts ),
363+ ID : fmt .Sprintf ("123-%d" , opts ),
364+ Name : fmt .Sprintf ("functionname-%d" , opts ),
365+ })
366+ }))
367+
368+ authzCache := newAuthorizationCache (common .SystemTime (), 10 * time .Minute )
369+
370+ authorizer := & AuthzClient {
371+ httpClient : svr .Client (),
372+ location : svr .URL + "/api/v2/tenant/" ,
373+ cache : authzCache ,
374+ }
375+
376+ for i := 0 ; i < b .N ; i ++ {
377+ sfx := b .N / 1000
378+ _ , _ = authorizer .Authorize (
379+ NewAccessToken (fmt .Sprintf ("sometoken-%d" , sfx )),
380+ fmt .Sprintf ("ident-%d" , sfx ),
381+ fmt .Sprintf ("namespace-%d" , sfx ),
382+ fmt .Sprintf ("fnName-%d" , sfx ))
383+ }
384+ }
0 commit comments