Skip to content

Commit bfe7a79

Browse files
committed
fix ID handling, update unit tests
1 parent 0110fe6 commit bfe7a79

2 files changed

Lines changed: 33 additions & 19 deletions

File tree

pomerium/sync_api.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
"sigs.k8s.io/controller-runtime/pkg/log"
2525

2626
"github.com/pomerium/pomerium/config"
27-
"github.com/pomerium/pomerium/pkg/cryptutil"
2827
pb "github.com/pomerium/pomerium/pkg/grpc/config"
2928
"github.com/pomerium/sdk-go"
3029
"github.com/pomerium/sdk-go/proto/pomerium"
@@ -345,7 +344,7 @@ func (r *APIReconciler) SetConfig(ctx context.Context, cfg *model.Config) (chang
345344

346345
// Apply all Core defaults.
347346
mergedSettings := config.NewDefaultOptions()
348-
mergedSettings.ApplySettings(ctx, cryptutil.NewCertificatesIndex(), pbConfig.Settings)
347+
mergedSettings.ApplySettings(ctx, nil, pbConfig.Settings)
349348

350349
settings, err := convertProto[*pomerium.Settings](mergedSettings.ToProto().GetSettings())
351350
if err != nil {
@@ -359,6 +358,7 @@ func (r *APIReconciler) SetConfig(ctx context.Context, cfg *model.Config) (chang
359358
existing := resp.Msg.Settings
360359

361360
// Preserve any settings that cannot be set via the Pomerium CRD.
361+
settings.Id = existing.Id
362362
settings.AutoApplyChangesets = existing.AutoApplyChangesets
363363

364364
// Mask timestamp metadata.

pomerium/sync_api_test.go

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"sigs.k8s.io/controller-runtime/pkg/client"
2222
gateway_v1 "sigs.k8s.io/gateway-api/apis/v1"
2323

24+
"github.com/pomerium/pomerium/config"
2425
"github.com/pomerium/sdk-go/proto/pomerium"
2526

2627
icgv1alpha1 "github.com/pomerium/ingress-controller/apis/gateway/v1alpha1"
@@ -1028,6 +1029,9 @@ func TestAPIReconciler_SetConfig(t *testing.T) {
10281029
},
10291030
}
10301031

1032+
defaultSettings, err := convertProto[*pomerium.Settings](config.NewDefaultOptions().ToProto().GetSettings())
1033+
require.NoError(t, err)
1034+
10311035
t.Run("settings changed", func(t *testing.T) {
10321036
apiClient, _, r := setupReconciler(t)
10331037
ctx := t.Context()
@@ -1042,16 +1046,20 @@ func TestAPIReconciler_SetConfig(t *testing.T) {
10421046
},
10431047
}, nil)
10441048

1049+
expectedSettings := proto.CloneOf(defaultSettings)
1050+
proto.Merge(expectedSettings, &pomerium.Settings{
1051+
Id: new("settings-id-123"),
1052+
AuthenticateServiceUrl: new("https://authenticate.localhost.pomerium.io"),
1053+
IdpClientId: new("CLIENT_ID"),
1054+
IdpClientSecret: new("CLIENT_SECRET"),
1055+
IdpProvider: new("oidc"),
1056+
IdpProviderUrl: new("https://idp.example.com"),
1057+
PassIdentityHeaders: new(true),
1058+
})
1059+
10451060
// ...and then call UpdateSettings() once it knows there are changes to sync.
10461061
apiClient.EXPECT().UpdateSettings(ctx, RequestEq(&pomerium.UpdateSettingsRequest{
1047-
Settings: &pomerium.Settings{
1048-
AuthenticateServiceUrl: new("https://authenticate.localhost.pomerium.io"),
1049-
IdpClientId: new("CLIENT_ID"),
1050-
IdpClientSecret: new("CLIENT_SECRET"),
1051-
IdpProvider: new("oidc"),
1052-
IdpProviderUrl: new("https://idp.example.com"),
1053-
PassIdentityHeaders: new(true),
1054-
},
1062+
Settings: expectedSettings,
10551063
})).Return(&connect.Response[pomerium.UpdateSettingsResponse]{
10561064
Msg: &pomerium.UpdateSettingsResponse{},
10571065
}, nil)
@@ -1065,19 +1073,25 @@ func TestAPIReconciler_SetConfig(t *testing.T) {
10651073
apiClient, _, r := setupReconciler(t)
10661074
ctx := t.Context()
10671075

1076+
existingSettings := proto.CloneOf(defaultSettings)
1077+
proto.Merge(existingSettings, &pomerium.Settings{
1078+
Id: new("settings-id-123"),
1079+
1080+
AuthenticateServiceUrl: new("https://authenticate.localhost.pomerium.io"),
1081+
IdpClientId: new("CLIENT_ID"),
1082+
IdpClientSecret: new("CLIENT_SECRET"),
1083+
IdpProvider: new("oidc"),
1084+
IdpProviderUrl: new("https://idp.example.com"),
1085+
PassIdentityHeaders: new(true),
1086+
1087+
AutoApplyChangesets: new(true), // this setting should be ignored
1088+
})
1089+
10681090
// If the settings already match, there should be no UpdateSettings() call.
10691091
apiClient.EXPECT().GetSettings(ctx, connect.NewRequest(&pomerium.GetSettingsRequest{})).
10701092
Return(&connect.Response[pomerium.GetSettingsResponse]{
10711093
Msg: &pomerium.GetSettingsResponse{
1072-
Settings: &pomerium.Settings{
1073-
Id: new("settings-id-123"),
1074-
1075-
AuthenticateServiceUrl: new("https://authenticate.localhost.pomerium.io"),
1076-
IdpClientId: new("CLIENT_ID"),
1077-
IdpClientSecret: new("CLIENT_SECRET"),
1078-
IdpProvider: new("oidc"),
1079-
IdpProviderUrl: new("https://idp.example.com"),
1080-
PassIdentityHeaders: new(true)},
1094+
Settings: existingSettings,
10811095
},
10821096
}, nil)
10831097

0 commit comments

Comments
 (0)