@@ -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 ) {
0 commit comments