@@ -425,3 +425,65 @@ func BenchmarkProcessRequestOffThreadRedisRollingLimiter(b *testing.B) {
425425 })
426426 }
427427}
428+
429+ func TestOrganizationMonitor_RefreshOrgSession (t * testing.T ) {
430+ conf := func (globalConf * config.Config ) {
431+ globalConf .EnforceOrgQuotas = true
432+ globalConf .LocalSessionCache .DisableCacheSessionState = false
433+ }
434+
435+ ts := StartTest (conf )
436+ defer ts .Close ()
437+
438+ orgID := "test-org-refresh-" + uuid .New ()
439+
440+ // Build API
441+ ts .Gw .BuildAndLoadAPI (func (spec * APISpec ) {
442+ spec .UseKeylessAccess = true
443+ spec .OrgID = orgID
444+ spec .Proxy .ListenPath = "/"
445+ })
446+
447+ t .Run ("refreshOrgSession populates cache" , func (t * testing.T ) {
448+ // Create org session
449+ ts .Run (t , test.TestCase {
450+ Path : "/tyk/org/keys/" + orgID ,
451+ AdminAuth : true ,
452+ Method : http .MethodPost ,
453+ Code : http .StatusOK ,
454+ Data : map [string ]interface {}{
455+ "quota_max" : 10 ,
456+ "quota_remaining" : 10 ,
457+ "quota_renewal_rate" : 60 ,
458+ },
459+ })
460+
461+ ts .Gw .SessionCache .Flush ()
462+
463+ // Verify cache is empty
464+ _ , found := ts .Gw .SessionCache .Get (orgID )
465+ if found {
466+ t .Error ("Cache should be empty" )
467+ }
468+
469+ spec := ts .Gw .apisByID [ts .Gw .apiSpecs [0 ].APIID ]
470+ monitor := & OrganizationMonitor {
471+ BaseMiddleware : & BaseMiddleware {
472+ Spec : spec ,
473+ Gw : ts .Gw ,
474+ },
475+ }
476+
477+ // Call refreshOrgSession
478+ monitor .refreshOrgSession (orgID )
479+
480+ // Wait a bit for async operation
481+ time .Sleep (50 * time .Millisecond )
482+
483+ // Verify cache is now populated
484+ _ , found = ts .Gw .SessionCache .Get (orgID )
485+ if ! found {
486+ t .Error ("Cache should be populated after refreshOrgSession" )
487+ }
488+ })
489+ }
0 commit comments