Skip to content
49 changes: 21 additions & 28 deletions ably/auth_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/ably/ably-go/internal/ablytest"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func single() *ably.PaginateParams {
Expand Down Expand Up @@ -134,7 +135,7 @@ func TestAuth_TokenAuth(t *testing.T) {
"want url.Scheme=http; got %s", requestUrl.Scheme)
rec.Reset()
tok, err := client.Auth.Authorize(context.Background(), nil)
assert.NoError(t, err,
require.NoError(t, err,
"Authorize()=%v", err)
// Call to Authorize should always refresh the token.
assert.Equal(t, 1, rec.Len(),
Expand Down Expand Up @@ -162,7 +163,7 @@ func TestAuth_TokenAuth_Renew(t *testing.T) {
TTL: time.Second.Milliseconds(),
}
tok, err := client.Auth.Authorize(context.Background(), params)
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, 1, rec.Len(),
"want rec.Len()=1; got %d", rec.Len())
ttl := tok.ExpireTime().Sub(tok.IssueTime())
Expand Down Expand Up @@ -197,7 +198,7 @@ func TestAuth_TokenAuth_Renew(t *testing.T) {
opts = app.Options(opts...)
opts = append(opts, ably.WithKey(""), ably.WithTokenDetails(tok))
client, err = ably.NewREST(opts...)
assert.NoError(t, err,
require.NoError(t, err,
"NewREST()=%v", err)
_, err = client.Stats().Pages(context.Background())
assert.Error(t, err)
Expand Down Expand Up @@ -250,7 +251,7 @@ func TestAuth_RequestToken(t *testing.T) {
ably.AuthWithCallback(server.Callback(callback)),
}
tokCallback, err := client.Auth.RequestToken(context.Background(), nil, authOpts...)
assert.NoError(t, err,
require.NoError(t, err,
"RequestToken()=%v (callback=%s)", err, callback)
// Ensure no requests to Ably servers were made.
assert.Equal(t, 0, rec.Len(),
Expand All @@ -268,7 +269,7 @@ func TestAuth_RequestToken(t *testing.T) {
ably.AuthWithCallback(server.Callback("request")),
}
tokCallback, err := client.Auth.RequestToken(context.Background(), nil, authOpts...)
assert.NoError(t, err,
require.NoError(t, err,
"RequestToken()=%v", err)
assert.Equal(t, 1, rec.Len(),
"want rec.Len()=1; got %d", rec.Len())
Expand Down Expand Up @@ -301,7 +302,7 @@ func TestAuth_RequestToken(t *testing.T) {
}

tokURL, err := client.Auth.RequestToken(context.Background(), params, authOpts...)
assert.NoError(t, err,
require.NoError(t, err,
"RequestToken()=%v (method=%s)", err, method)
assert.NotEqual(t, tokURL.Token, token2.Token,
"want tokURL.Token != token2.Token: %s (method=%s)", tokURL.Token, method)
Expand Down Expand Up @@ -333,7 +334,7 @@ func TestAuth_RequestToken(t *testing.T) {
ably.WithToken(tokURL.Token),
)
c, err := ably.NewREST(optsURL...)
assert.NoError(t, err,
require.NoError(t, err,
"NewREST()=%v", err)
_, err = c.Stats().Pages(context.Background())
assert.NoError(t, err,
Expand Down Expand Up @@ -381,11 +382,10 @@ func TestAuth_JWT_Token_RSA8c(t *testing.T) {
assert.True(t, strings.HasPrefix(jwt, "ey"))

rec, optn := ablytest.NewHttpRecorder()
rest, err := ably.NewREST(
rest, err := ably.NewREST(app.Options(
ably.WithToken(jwt),
ably.WithEndpoint(app.Endpoint),
optn[0],
)
)...)
assert.NoError(t, err, "rest()=%v", err)

_, err = rest.Stats().Pages(context.Background())
Expand All @@ -404,12 +404,11 @@ func TestAuth_JWT_Token_RSA8c(t *testing.T) {
app := ablytest.MustSandbox()

rec, optn := ablytest.NewHttpRecorder()
rest, err := ably.NewREST(
rest, err := ably.NewREST(app.Options(
ably.WithAuthURL(ablytest.CREATE_JWT_URL),
ably.WithAuthParams(app.GetJwtAuthParams(30*time.Second, false)),
ably.WithEndpoint(app.Endpoint),
optn[0],
)
)...)
assert.NoError(t, err, "rest()=%v", err)

_, err = rest.Stats().Pages(context.Background())
Expand Down Expand Up @@ -448,11 +447,10 @@ func TestAuth_JWT_Token_RSA8c(t *testing.T) {
})

rec, optn := ablytest.NewHttpRecorder()
rest, err := ably.NewREST(
ably.WithEndpoint(app.Endpoint),
rest, err := ably.NewREST(app.Options(
authCallback,
optn[0],
)
)...)
assert.NoError(t, err)

_, err = rest.Stats().Pages(context.Background())
Expand All @@ -473,12 +471,11 @@ func TestAuth_JWT_Token_RSA8c(t *testing.T) {
app := ablytest.MustSandbox()

rec, optn := ablytest.NewHttpRecorder()
rest, err := ably.NewREST(
rest, err := ably.NewREST(app.Options(
ably.WithAuthURL(ablytest.CREATE_JWT_URL),
ably.WithAuthParams(app.GetJwtAuthParams(30*time.Second, true)),
ably.WithEndpoint(app.Endpoint),
optn[0],
)
)...)
assert.NoError(t, err, "rest()=%v", err)

_, err = rest.Stats().Pages(context.Background())
Expand All @@ -502,14 +499,14 @@ func TestAuth_ReuseClientID(t *testing.T) {
ClientID: "reuse-me",
}
tok, err := client.Auth.Authorize(context.Background(), params)
assert.NoError(t, err,
require.NoError(t, err,
"Authorize()=%v", err)
assert.Equal(t, params.ClientID, tok.ClientID,
"want ClientID=%q; got %q", params.ClientID, tok.ClientID)
assert.Equal(t, params.ClientID, client.Auth.ClientID(),
"want ClientID=%q; got %q", params.ClientID, client.Auth.ClientID())
tok2, err := client.Auth.Authorize(context.Background(), nil)
assert.NoError(t, err,
require.NoError(t, err,
"Authorize()=%v", err)
assert.Equal(t, params.ClientID, tok2.ClientID,
"want ClientID=%q; got %q", params.ClientID, tok2.ClientID)
Expand All @@ -532,7 +529,7 @@ func TestAuth_RequestToken_PublishClientID(t *testing.T) {

for i, cas := range cases {
rclient, err := ably.NewREST(app.Options()...)
assert.NoError(t, err)
require.NoError(t, err)
params := &ably.TokenParams{
ClientID: cas.authAs,
}
Expand Down Expand Up @@ -718,13 +715,13 @@ func TestAuth_CreateTokenRequest(t *testing.T) {
})
t.Run("RSA9c must generate a unique 16+ character nonce", func(t *testing.T) {
req, err := client.Auth.CreateTokenRequest(params, opts...)
assert.NoError(t, err)
require.NoError(t, err)
assert.GreaterOrEqual(t, len(req.Nonce), 16,
"want len(nonce)>=16; got %d", len(req.Nonce))
})
t.Run("RSA9g generate a signed request", func(t *testing.T) {
req, err := client.Auth.CreateTokenRequest(nil)
assert.NoError(t, err,
require.NoError(t, err,
"CreateTokenRequest()=%v", err)
assert.NotEqual(t, "", req.MAC,
"want mac to be not empty")
Expand Down Expand Up @@ -780,7 +777,6 @@ func TestAuth_IgnoreTimestamp_QueryTime(t *testing.T) {
}{
"Should not save query time and timestamp when WithQueryTime is false and token params has no timestamp": {
opt: []ably.ClientOption{
ably.WithTLS(true),
ably.WithUseTokenAuth(true),
ably.WithQueryTime(false),
},
Expand All @@ -794,7 +790,6 @@ func TestAuth_IgnoreTimestamp_QueryTime(t *testing.T) {
},
"Should not save query time and timestamp when WithQueryTime is true and token params has no timestamp": {
opt: []ably.ClientOption{
ably.WithTLS(true),
ably.WithUseTokenAuth(true),
ably.WithQueryTime(true),
},
Expand All @@ -808,7 +803,6 @@ func TestAuth_IgnoreTimestamp_QueryTime(t *testing.T) {
},
"Should not save query time and timestamp when WithQueryTime is true and token params has a timestamp": {
opt: []ably.ClientOption{
ably.WithTLS(true),
ably.WithUseTokenAuth(true),
ably.WithQueryTime(true),
},
Expand All @@ -822,7 +816,6 @@ func TestAuth_IgnoreTimestamp_QueryTime(t *testing.T) {
},
"Should not save query time and timestamp when WithQueryTime is false and token params has a timestamp": {
opt: []ably.ClientOption{
ably.WithTLS(true),
ably.WithUseTokenAuth(true),
ably.WithQueryTime(false),
},
Expand Down
15 changes: 8 additions & 7 deletions ably/http_paginated_response_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,17 @@ import (
"github.com/ably/ably-go/internal/ablytest"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestHTTPPaginatedFallback(t *testing.T) {
app, err := ablytest.NewSandbox()
assert.NoError(t, err)
require.NoError(t, err)
opts := app.Options(ably.WithUseBinaryProtocol(false),
ably.WithEndpoint("ably.invalid"),
ably.WithFallbackHosts(nil))
client, err := ably.NewREST(opts...)
assert.NoError(t, err)
require.NoError(t, err)
t.Run("request_time", func(t *testing.T) {
_, err := client.Request("get", "/time").Pages(context.Background())
assert.Error(t, err)
Expand All @@ -32,12 +33,12 @@ func TestHTTPPaginatedFallback(t *testing.T) {

func TestHTTPPaginatedResponse(t *testing.T) {
app, err := ablytest.NewSandbox()
assert.NoError(t, err)
require.NoError(t, err)
client, err := ably.NewREST(app.Options()...)
assert.NoError(t, err)
require.NoError(t, err)
t.Run("request_time", func(t *testing.T) {
res, err := client.Request("get", "/time").Pages(context.Background())
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, http.StatusOK, res.StatusCode(),
"expected %d got %d", http.StatusOK, res.StatusCode())
assert.True(t, res.Success(), "expected success to be true")
Expand All @@ -51,7 +52,7 @@ func TestHTTPPaginatedResponse(t *testing.T) {

t.Run("request_404", func(t *testing.T) {
res, err := client.Request("get", "/keys/ablyjs.test/requestToken").Pages(context.Background())
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, http.StatusNotFound, res.StatusCode(),
"expected %d got %d", http.StatusNotFound, res.StatusCode())
assert.Equal(t, ably.ErrNotFound, res.ErrorCode(),
Expand All @@ -73,7 +74,7 @@ func TestHTTPPaginatedResponse(t *testing.T) {
t.Run("post", func(t *testing.T) {
for _, message := range msgs {
res, err := client.Request("POST", channelPath, ably.RequestWithBody(message)).Pages(context.Background())
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, http.StatusCreated, res.StatusCode(),
"expected %d got %d", http.StatusCreated, res.StatusCode())
assert.True(t, res.Success(),
Expand Down
9 changes: 5 additions & 4 deletions ably/proto_message_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/ably/ably-go/internal/ablytest"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestMessage_CryptoDataFixtures_RSL6a1_RSL5b_RSL5c(t *testing.T) {
Expand Down Expand Up @@ -47,14 +48,14 @@ func TestMessage_CryptoDataFixtures_RSL6a1_RSL5b_RSL5c(t *testing.T) {
assert.NoError(t, err)

encoded, err = ably.MessageWithDecodedData(encoded, cipher)
assert.NoError(t, err)
require.NoError(t, err)

var encrypted ably.Message
err = json.Unmarshal(item.Encoded, &encrypted)
assert.NoError(t, err)

encrypted, err = ably.MessageWithDecodedData(encrypted, cipher)
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, encoded.Name, encrypted.Name,
"expected %s got %s", encoded.Name, encrypted.Name)
assert.Equal(t, encoded.Data, encrypted.Data,
Expand Down Expand Up @@ -98,14 +99,14 @@ func TestMessage_CryptoDataFixtures_RSL6a1_RSL5b_RSL5c_TM3(t *testing.T) {
assert.NoError(t, err)

encoded, err = ably.MessageWithDecodedData(encoded, cipher)
assert.NoError(t, err)
require.NoError(t, err)

var encrypted ably.Message
err = json.Unmarshal(item.Encoded, &encrypted)
assert.NoError(t, err)

encrypted, err = ably.MessageWithDecodedData(encrypted, cipher)
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, encoded.Name, encrypted.Name)
assert.Equal(t, encoded.Data, encrypted.Data)
}
Expand Down
5 changes: 3 additions & 2 deletions ably/realtime_channel_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/ably/ably-go/internal/ablytest"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func expectMsg(ch <-chan *ably.Message, name string, data interface{}, t time.Duration, received bool) error {
Expand Down Expand Up @@ -111,7 +112,7 @@ func TestRealtimeChannel_Subscribe(t *testing.T) {

func TestRealtimeChannel_SubscriptionFilters(t *testing.T) {
app, err := ablytest.NewSandbox()
assert.NoError(t, err)
require.NoError(t, err)
options := app.Options()
restClient, err := ably.NewREST(options...)
assert.NoError(t, err)
Expand Down Expand Up @@ -173,7 +174,7 @@ func TestRealtimeChannel_SubscriptionFilters(t *testing.T) {
unsub, err := rtDerivedChannel.SubscribeAll(ctx, func(msg *ably.Message) {
filteredMessages <- msg
})
assert.NoError(t, err)
require.NoError(t, err)
defer unsub()

unfilteredMessages := make(chan *ably.Message, 10)
Expand Down
Loading
Loading