66
77 "github.com/launchdarkly/go-sdk-common/v3/ldlogtest"
88 "github.com/launchdarkly/ld-relay/v8/config"
9+ "github.com/launchdarkly/ld-relay/v8/internal/util"
910 "github.com/stretchr/testify/assert"
1011 "github.com/stretchr/testify/require"
1112)
@@ -53,7 +54,7 @@ func TestReconcileAnchorOnly(t *testing.T) {
5354 anchor := config .SDKKey ("anchor" )
5455 now := time .Now ()
5556
56- r .Reconcile (mustBuild (t , NewAcceptedSetBuilder ().WithAnchor (anchor )), now )
57+ r .Reconcile (mustBuild (t , NewAcceptedSetBuilder ().WithAnchor (SDKKeyParams { Value : anchor } )), now )
5758 additions , expirations := r .StepTime (now )
5859
5960 assert .ElementsMatch (t , []SDKCredential {anchor }, additions )
@@ -70,7 +71,7 @@ func TestReconcileMultipleSDKKeys(t *testing.T) {
7071 now := time .Now ()
7172
7273 r .Reconcile (
73- mustBuild (t , NewAcceptedSetBuilder ().WithAnchor (anchor ).WithSDKKey (other )), now )
74+ mustBuild (t , NewAcceptedSetBuilder ().WithAnchor (SDKKeyParams { Value : anchor } ).WithSDKKey (SDKKeyParams { Value : other } )), now )
7475 additions , expirations := r .StepTime (now )
7576
7677 // Both server keys are accepted; only the anchor is primary.
@@ -89,7 +90,7 @@ func TestReconcileMultipleMobileKeys(t *testing.T) {
8990 now := time .Now ()
9091
9192 r .Reconcile (
92- mustBuild (t , NewAcceptedSetBuilder ().WithAnchor (anchor ).WithPrimaryMobileKey (mob1 ).WithMobileKey (mob2 )), now )
93+ mustBuild (t , NewAcceptedSetBuilder ().WithAnchor (SDKKeyParams { Value : anchor } ).WithPrimaryMobileKey (MobileKeyParams { Value : mob1 } ).WithMobileKey (MobileKeyParams { Value : mob2 } )), now )
9394 additions , _ := r .StepTime (now )
9495
9596 // Every mobile key is accepted; the designated one is the primary.
@@ -106,11 +107,11 @@ func TestReconcileRevokesOmittedKeys(t *testing.T) {
106107 now := time .Now ()
107108
108109 r .Reconcile (
109- mustBuild (t , NewAcceptedSetBuilder ().WithAnchor (anchor ).WithSDKKey (other ).WithPrimaryMobileKey (mob )), now )
110+ mustBuild (t , NewAcceptedSetBuilder ().WithAnchor (SDKKeyParams { Value : anchor } ).WithSDKKey (SDKKeyParams { Value : other } ).WithPrimaryMobileKey (MobileKeyParams { Value : mob } )), now )
110111 r .StepTime (now )
111112
112113 // Reconciling to just the anchor revokes the omitted server and mobile keys.
113- r .Reconcile (mustBuild (t , NewAcceptedSetBuilder ().WithAnchor (anchor )), now )
114+ r .Reconcile (mustBuild (t , NewAcceptedSetBuilder ().WithAnchor (SDKKeyParams { Value : anchor } )), now )
114115 additions , expirations := r .StepTime (now )
115116
116117 assert .Empty (t , additions )
@@ -132,10 +133,10 @@ func TestReconcileAcceptsExpiringKeysAsData(t *testing.T) {
132133
133134 r .Reconcile (
134135 mustBuild (t , NewAcceptedSetBuilder ().
135- WithAnchor (anchor ).
136- WithExpiringSDKKey ( expiringSDK , now .Add (time .Hour )).
137- WithPrimaryMobileKey (mob ).
138- WithExpiringMobileKey ( expiringMobile , now .Add (time .Hour ))),
136+ WithAnchor (SDKKeyParams { Value : anchor } ).
137+ WithSDKKey ( SDKKeyParams { Value : expiringSDK , Expiry : util . PtrOrNil ( now .Add (time .Hour ))} ).
138+ WithPrimaryMobileKey (MobileKeyParams { Value : mob } ).
139+ WithMobileKey ( MobileKeyParams { Value : expiringMobile , Expiry : util . PtrOrNil ( now .Add (time .Hour ))} )),
139140 now )
140141 additions , expirations := r .StepTime (now )
141142
@@ -158,9 +159,9 @@ func TestReconcilePrimaryMobileKeyIsAlwaysAccepted(t *testing.T) {
158159 now := time .Unix (1000 , 0 )
159160
160161 set := mustBuild (t , NewAcceptedSetBuilder ().
161- WithAnchor (anchor ).
162- WithExpiringMobileKey ( mob , now .Add (- time .Hour )). // already expired in the payload...
163- WithPrimaryMobileKey (mob )) // ...but designated as the primary
162+ WithAnchor (SDKKeyParams { Value : anchor } ).
163+ WithMobileKey ( MobileKeyParams { Value : mob , Expiry : util . PtrOrNil ( now .Add (- time .Hour ))} ). // already expired in the payload...
164+ WithPrimaryMobileKey (MobileKeyParams { Value : mob })) // ...but designated as the primary
164165 r .Reconcile (set , now )
165166 r .StepTime (now )
166167
@@ -184,10 +185,10 @@ func TestReconcileExpiringKeysAreEvictedByStepTime(t *testing.T) {
184185
185186 r .Reconcile (
186187 mustBuild (t , NewAcceptedSetBuilder ().
187- WithAnchor (anchor ).
188- WithExpiringSDKKey ( expiringSDK , expiry ).
189- WithPrimaryMobileKey (mob ).
190- WithExpiringMobileKey ( expiringMobile , expiry )),
188+ WithAnchor (SDKKeyParams { Value : anchor } ).
189+ WithSDKKey ( SDKKeyParams { Value : expiringSDK , Expiry : util . PtrOrNil ( expiry )} ).
190+ WithPrimaryMobileKey (MobileKeyParams { Value : mob } ).
191+ WithMobileKey ( MobileKeyParams { Value : expiringMobile , Expiry : util . PtrOrNil ( expiry )} )),
191192 now )
192193 additions , expirations := r .StepTime (now )
193194 require .ElementsMatch (t , []SDKCredential {anchor , expiringSDK , mob , expiringMobile }, additions )
@@ -218,8 +219,8 @@ func TestReconcileAlreadyExpiredKeyIsIgnoredOnAdd(t *testing.T) {
218219
219220 r .Reconcile (
220221 mustBuild (t , NewAcceptedSetBuilder ().
221- WithAnchor (anchor ).
222- WithExpiringSDKKey ( staleKey , alreadyExpired )),
222+ WithAnchor (SDKKeyParams { Value : anchor } ).
223+ WithSDKKey ( SDKKeyParams { Value : staleKey , Expiry : util . PtrOrNil ( alreadyExpired )} )),
223224 now )
224225 additions , expirations := r .StepTime (now )
225226
@@ -242,17 +243,17 @@ func TestReconcileDeExpiryRestoresKey(t *testing.T) {
242243 // First reconcile: key is accepted with a future expiry.
243244 r .Reconcile (
244245 mustBuild (t , NewAcceptedSetBuilder ().
245- WithAnchor (anchor ).
246- WithExpiringSDKKey ( key , expiry )),
246+ WithAnchor (SDKKeyParams { Value : anchor } ).
247+ WithSDKKey ( SDKKeyParams { Value : key , Expiry : util . PtrOrNil ( expiry )} )),
247248 now )
248249 r .StepTime (now )
249250 require .ElementsMatch (t , []SDKCredential {key }, r .DeprecatedCredentials ())
250251
251252 // Second reconcile: same key, no expiry (de-expiry).
252253 r .Reconcile (
253254 mustBuild (t , NewAcceptedSetBuilder ().
254- WithAnchor (anchor ).
255- WithSDKKey (key )),
255+ WithAnchor (SDKKeyParams { Value : anchor } ).
256+ WithSDKKey (SDKKeyParams { Value : key } )),
256257 now )
257258 r .StepTime (now )
258259
0 commit comments