diff --git a/management/server/store/sql_store_service_test.go b/management/server/store/sql_store_service_test.go index 0e14fbdab..421b0f5c3 100644 --- a/management/server/store/sql_store_service_test.go +++ b/management/server/store/sql_store_service_test.go @@ -133,3 +133,42 @@ func TestSqlStore_GetAccount_ServiceTargetOptionsRoundtrip(t *testing.T) { assert.True(t, tg.Options.DisableAccessLog, "options disable access log") }) } + +func TestSqlStore_GetAccount_ServiceRestrictionsRoundtrip(t *testing.T) { + if os.Getenv("CI") == "true" && (runtime.GOOS == "darwin" || runtime.GOOS == "windows") { + t.Skip("skip CI tests on darwin and windows") + } + + runTestForAllEngines(t, "", func(t *testing.T, store Store) { + ctx := context.Background() + account := newAccountWithId(ctx, "account_svc_restrictions", "testuser", "") + require.NoError(t, store.SaveAccount(ctx, account)) + + svc := &rpservice.Service{ + ID: "svc-restrictions", + AccountID: account.Id, + Name: "restricted-svc", + Domain: "restricted.example", + Enabled: true, + Mode: rpservice.ModeHTTP, + Restrictions: rpservice.AccessRestrictions{ + AllowedCIDRs: []string{"203.0.113.0/24"}, + AllowedCountries: []string{"US"}, + AllowMatch: "any", + }, + } + require.NoError(t, store.CreateService(ctx, svc)) + + loaded, err := store.GetAccount(ctx, account.Id) + require.NoError(t, err) + require.Len(t, loaded.Services, 1) + + // Restrictions are stored as a JSON blob; confirm the whole struct, + // including allow_match, survives the read path (Postgres pgx path + // included via runTestForAllEngines). + got := loaded.Services[0].Restrictions + assert.Equal(t, []string{"203.0.113.0/24"}, got.AllowedCIDRs) + assert.Equal(t, []string{"US"}, got.AllowedCountries) + assert.Equal(t, "any", got.AllowMatch) + }) +}