Skip to content

Commit 2520328

Browse files
committed
dev: Fix tests and linter issues
1 parent b40e7b0 commit 2520328

3 files changed

Lines changed: 19 additions & 11 deletions

File tree

pkg/identityserver/bunstore/oauth_store.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,9 @@ func (s *oauthStore) GetAccessTokenWithSession(
713713
Relation("Client", func(q *bun.SelectQuery) *bun.SelectQuery {
714714
return q.Column("client_id")
715715
}).
716-
Relation("UserSession")
716+
Relation("UserSession", func(q *bun.SelectQuery) *bun.SelectQuery {
717+
return q.ExcludeColumn("session_secret")
718+
})
717719

718720
if err := selectQuery.Scan(ctx); err != nil {
719721
err = storeutil.WrapDriverError(err)

pkg/identityserver/entity_access_test.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,17 @@ func TestEntityAccess(t *testing.T) {
7272
oauthClient := p.NewClient(oauthUsr.GetOrganizationOrUserIdentifiers())
7373
oauthClient.Rights = []ttnpb.Right{ttnpb.Right_RIGHT_USER_ALL}
7474

75-
// Session that is already expired.
76-
expiredSession := p.NewUserSession(oauthUsr.GetIds())
77-
p.UserSessions[len(p.UserSessions)-1].ExpiresAt = timestamppb.New(time.Now().Add(-10 * time.Minute))
75+
// Session that is already expired. CreateSession assigns the session ID,
76+
// so we reference the population slice entry to read the actual ID after
77+
// Populate runs.
78+
p.NewUserSession(oauthUsr.GetIds())
79+
expiredSession := p.UserSessions[len(p.UserSessions)-1]
80+
expiredSession.ExpiresAt = timestamppb.New(time.Now().Add(-10 * time.Minute))
7881

7982
// Session that is still valid.
80-
validSession := p.NewUserSession(oauthUsr.GetIds())
81-
p.UserSessions[len(p.UserSessions)-1].ExpiresAt = timestamppb.New(time.Now().Add(10 * time.Minute))
83+
p.NewUserSession(oauthUsr.GetIds())
84+
validSession := p.UserSessions[len(p.UserSessions)-1]
85+
validSession.ExpiresAt = timestamppb.New(time.Now().Add(10 * time.Minute))
8286

8387
// Generate access token bearer strings. The stored AccessToken is the hashed key.
8488
newBearerAccessToken := func() (bearer, tokenID, hashed string) {
@@ -250,23 +254,23 @@ func TestEntityAccess(t *testing.T) {
250254
}
251255
})
252256

253-
t.Run("Access Token with Valid Session", func(t *testing.T) {
257+
t.Run("Access Token with Valid Session", func(t *testing.T) { // nolint:paralleltest
254258
a, ctx := test.New(t)
255259
authInfo, err := cli.AuthInfo(ctx, ttnpb.Empty, bearerCreds(validSessionToken))
256260
if a.So(err, should.BeNil) && a.So(authInfo, should.NotBeNil) {
257261
a.So(authInfo.GetOauthAccessToken(), should.NotBeNil)
258262
}
259263
})
260264

261-
t.Run("Access Token with Expired Session", func(t *testing.T) {
265+
t.Run("Access Token with Expired Session", func(t *testing.T) { // nolint:paralleltest
262266
a, ctx := test.New(t)
263267
_, err := cli.AuthInfo(ctx, ttnpb.Empty, bearerCreds(expiredSessionToken))
264268
if a.So(err, should.NotBeNil) {
265269
a.So(errors.IsUnauthenticated(err), should.BeTrue)
266270
}
267271
})
268272

269-
t.Run("Access Token with Missing Session", func(t *testing.T) {
273+
t.Run("Access Token with Missing Session", func(t *testing.T) { // nolint:paralleltest
270274
a, ctx := test.New(t)
271275
_, err := cli.AuthInfo(ctx, ttnpb.Empty, bearerCreds(missingSessionToken))
272276
if a.So(err, should.NotBeNil) {

pkg/oauth/server_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -813,13 +813,15 @@ func TestTokenExchange(t *testing.T) {
813813
Method: "POST",
814814
Path: "/oauth/token",
815815
Body: map[string]string{
816-
"grant_type": "refresh_token",
817-
"refresh_token": "OJSWM.IBTFXELDVVT64Y26IZZFFNSL7GWZY2Y3ALQQI3A.GCPIASDUP7UZJ6YL5OP2ESZB7CKRFV4JJQYTMDOSDIOE7O75IAMQ",
816+
"grant_type": "refresh_token",
817+
"refresh_token": "OJSWM.IBTFXELDVVT64Y26IZZFFNSL7GWZY2Y3ALQQI3A" +
818+
".GCPIASDUP7UZJ6YL5OP2ESZB7CKRFV4JJQYTMDOSDIOE7O75IAMQ",
818819
"client_id": "client",
819820
"client_secret": "secret",
820821
},
821822
ExpectedCode: http.StatusUnauthorized,
822823
StoreCheck: func(t *testing.T, s *mockStore) {
824+
t.Helper()
823825
a := assertions.New(t)
824826
a.So(s.calls, should.Contain, "GetAccessToken")
825827
a.So(s.calls, should.Contain, "GetSession")

0 commit comments

Comments
 (0)