Skip to content

Commit c258e5d

Browse files
committed
Add test
1 parent 87422ef commit c258e5d

1 file changed

Lines changed: 34 additions & 1 deletion

File tree

gateway/mw_organisation_activity_test.go

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ func TestOrganizationMonitor_RefreshOrgSession(t *testing.T) {
444444
spec.Proxy.ListenPath = "/"
445445
})
446446

447-
t.Run("refreshOrgSession populates cache", func(t *testing.T) {
447+
t.Run("refreshOrgSession populates cache when session found", func(t *testing.T) {
448448
// Create org session
449449
ts.Run(t, test.TestCase{
450450
Path: "/tyk/org/keys/" + orgID,
@@ -486,4 +486,37 @@ func TestOrganizationMonitor_RefreshOrgSession(t *testing.T) {
486486
t.Error("Cache should be populated after refreshOrgSession")
487487
}
488488
})
489+
490+
t.Run("refreshOrgSession sets OrgHasNoSession when session not found", func(t *testing.T) {
491+
nonExistentOrgID := "test-org-nonexistent-" + uuid.New()
492+
493+
// Build API with non-existent org
494+
spec := ts.Gw.BuildAndLoadAPI(func(spec *APISpec) {
495+
spec.UseKeylessAccess = true
496+
spec.OrgID = nonExistentOrgID
497+
spec.Proxy.ListenPath = "/nonexistent/"
498+
})[0]
499+
500+
// Verify OrgHasNoSession is initially false
501+
if spec.OrgHasNoSession {
502+
t.Error("OrgHasNoSession should initially be false")
503+
}
504+
505+
monitor := &OrganizationMonitor{
506+
BaseMiddleware: &BaseMiddleware{
507+
Spec: spec,
508+
Gw: ts.Gw,
509+
},
510+
}
511+
512+
monitor.refreshOrgSession(nonExistentOrgID)
513+
514+
// Wait for async operation
515+
time.Sleep(50 * time.Millisecond)
516+
517+
// Verify OrgHasNoSession is now true
518+
if !monitor.getOrgHasNoSession() {
519+
t.Error("OrgHasNoSession should be true after refreshOrgSession for non-existent org")
520+
}
521+
})
489522
}

0 commit comments

Comments
 (0)