Skip to content

Commit

Permalink
Updated JWT tests with right spec annotations, added missing assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
sacOO7 committed Sep 5, 2024
1 parent 1ffeb0f commit 3bc352c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
14 changes: 11 additions & 3 deletions ably/auth_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,9 +344,17 @@ func TestAuth_RequestToken(t *testing.T) {
}
}

func TestAuth_JWT_Token(t *testing.T) {
func TestAuth_JWT_Token_RSA8c(t *testing.T) {

t.Run("Should be able to authenticate using authURL", func(t *testing.T) {
t.Run("Get JWT from echo server", func(t *testing.T) {
app := ablytest.MustSandbox(nil)
defer safeclose(t, app)
jwt, err := app.CreateJwt(3 * time.Second)
assert.NoError(t, err)
assert.True(t, strings.HasPrefix(jwt, "ey"))
})

t.Run("RSA8g, RSA3d: Should be able to authenticate using authURL", func(t *testing.T) {
app := ablytest.MustSandbox(nil)
defer safeclose(t, app)

Expand Down Expand Up @@ -382,7 +390,7 @@ func TestAuth_JWT_Token(t *testing.T) {
assert.Equal(t, "Bearer "+encodedToken, statsRequest.Header.Get("Authorization"))
})

t.Run("Should be able to authenticate using authCallback", func(t *testing.T) {
t.Run("RSA8g, RSA3d: Should be able to authenticate using authCallback", func(t *testing.T) {
app := ablytest.MustSandbox(nil)
defer safeclose(t, app)

Expand Down
8 changes: 7 additions & 1 deletion ably/realtime_conn_spec_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3022,7 +3022,7 @@ func TestRealtimeConn_RTC8a_ExplicitAuthorizeWhileConnected(t *testing.T) {
ablytest.Instantly.Recv(t, nil, authorizeDone, t.Fatalf)
})

t.Run("RTC8a4: reauthorize with JWT token", func(t *testing.T) {
t.Run("RTC8a4, RSA3d: reauthorize with JWT token", func(t *testing.T) {
t.Parallel()
app := ablytest.MustSandbox(nil)
defer safeclose(t, app)
Expand All @@ -3039,9 +3039,11 @@ func TestRealtimeConn_RTC8a_ExplicitAuthorizeWhileConnected(t *testing.T) {
return ably.TokenString(jwtTokenString), nil
}

realtimeMsgRecorder := NewMessageRecorder()
realtime, err := ably.NewRealtime(
ably.WithAutoConnect(false),
ably.WithEnvironment(ablytest.Environment),
ably.WithDial(realtimeMsgRecorder.Dial),
ably.WithAuthCallback(authCallback))

assert.NoError(t, err)
Expand Down Expand Up @@ -3073,6 +3075,10 @@ func TestRealtimeConn_RTC8a_ExplicitAuthorizeWhileConnected(t *testing.T) {
assert.True(t, strings.HasPrefix(authCallbackTokens[0], "ey"))
assert.True(t, strings.HasPrefix(authCallbackTokens[1], "ey"))
assertUnique(t, authCallbackTokens)
// 2 Dial attempts made
assert.Len(t, realtimeMsgRecorder.URLs(), 2)
assert.Equal(t, authCallbackTokens[0], realtimeMsgRecorder.URLs()[0].Query().Get("access_token"))
assert.Equal(t, authCallbackTokens[1], realtimeMsgRecorder.URLs()[1].Query().Get("access_token"))
})

t.Run("RTC8a2: Failed reauth moves connection to FAILED", func(t *testing.T) {
Expand Down

0 comments on commit 3bc352c

Please sign in to comment.