Skip to content

Commit

Permalink
fix bug with immediate revocation
Browse files Browse the repository at this point in the history
  • Loading branch information
cwaldren-ld committed Jun 19, 2024
1 parent 4b7b2ba commit 1c4a165
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
7 changes: 5 additions & 2 deletions internal/credential/rotator.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,9 @@ func (r *Rotator) RotateMobileKey(mobileKey config.MobileKey) {
}

func (r *Rotator) swapPrimaryKey(newKey config.SDKKey) config.SDKKey {
if newKey == r.SDKKey() {
if newKey == r.primarySdkKey {
// There's no swap to be done, we already are using this as primary.
return newKey
return ""
}
previous := r.primarySdkKey
r.primarySdkKey = newKey
Expand All @@ -195,6 +195,9 @@ func (r *Rotator) swapPrimaryKey(newKey config.SDKKey) config.SDKKey {
return previous
}
func (r *Rotator) RotateSDKKey(sdkKey config.SDKKey, deprecation *DeprecationNotice) {
r.mu.Lock()
defer r.mu.Unlock()

previous := r.swapPrimaryKey(sdkKey)
// Immediately revoke the previous SDK key if there's no explicit deprecation notice, otherwise it would
// hang around forever.
Expand Down
8 changes: 4 additions & 4 deletions relay/autoconfig_actions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ func TestAutoConfigInit(t *testing.T) {
if client1.Key == testAutoConfEnv2.SDKKey() {
client1, client2 = client2, client1
}
assert.Equal(t, testAutoConfEnv1.sdkKey, client1.Key)
assert.Equal(t, testAutoConfEnv2.sdkKey, client2.Key)
assert.Equal(t, testAutoConfEnv1.SDKKey(), client1.Key)
assert.Equal(t, testAutoConfEnv2.SDKKey(), client2.Key)

env1 := p.awaitEnvironment(testAutoConfEnv1.id)
assertEnvProps(t, testAutoConfEnv1.params(), env1)
Expand Down Expand Up @@ -184,15 +184,15 @@ func TestAutoConfigAddEnvironment(t *testing.T) {
initialEvent := makeAutoConfPutEvent(testAutoConfEnv1)
autoConfTest(t, testAutoConfDefaultConfig, &initialEvent, func(p autoConfTestParams) {
client1 := p.awaitClient()
assert.Equal(t, testAutoConfEnv1.sdkKey, client1.Key)
assert.Equal(t, testAutoConfEnv1.SDKKey(), client1.Key)

env1 := p.awaitEnvironment(testAutoConfEnv1.id)
assertEnvProps(t, testAutoConfEnv1.params(), env1)

p.stream.Enqueue(makeAutoConfPatchEvent(testAutoConfEnv2))

client2 := p.awaitClient()
assert.Equal(t, testAutoConfEnv2.sdkKey, client2.Key)
assert.Equal(t, testAutoConfEnv2.SDKKey(), client2.Key)

env2 := p.awaitEnvironment(testAutoConfEnv2.id)
p.assertEnvLookup(env2, testAutoConfEnv2.params())
Expand Down
4 changes: 4 additions & 0 deletions relay/testutils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type relayTestHelper struct {
}

func (h relayTestHelper) awaitEnvironment(envID c.EnvironmentID) relayenv.EnvContext {
h.t.Helper()
var e relayenv.EnvContext
var err error
require.Eventually(h.t, func() bool {
Expand All @@ -37,13 +38,16 @@ func (h relayTestHelper) awaitEnvironment(envID c.EnvironmentID) relayenv.EnvCon
}

func (h relayTestHelper) shouldNotHaveEnvironment(envID c.EnvironmentID, timeout time.Duration) {
h.t.Helper()
require.Eventually(h.t, func() bool {
_, err := h.relay.getEnvironment(sdkauth.New(envID))
return err != nil
}, timeout, time.Millisecond*5)
}

func (h relayTestHelper) assertEnvLookup(env relayenv.EnvContext, expected envfactory.EnvironmentParams) {
h.t.Helper()

foundEnv, err := h.relay.getEnvironment(sdkauth.New(expected.EnvID))
if assert.NoError(h.t, err) {
assert.Equal(h.t, env, foundEnv)
Expand Down

0 comments on commit 1c4a165

Please sign in to comment.