-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Expand file tree
/
Copy pathtoken_test.go
More file actions
32 lines (24 loc) · 835 Bytes
/
token_test.go
File metadata and controls
32 lines (24 loc) · 835 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package context
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
)
func TestGetTokenScopesForToken_MatchesBoundToken(t *testing.T) {
ctx := WithTokenScopesForToken(context.Background(), "token-a", []string{"repo"})
scopes, ok := GetTokenScopesForToken(ctx, "token-a")
assert.True(t, ok)
assert.Equal(t, []string{"repo"}, scopes)
scopes, ok = GetTokenScopesForToken(ctx, "token-b")
assert.False(t, ok)
assert.Nil(t, scopes)
}
func TestGetTokenScopesForToken_DoesNotReuseLegacyScopesForNonEmptyToken(t *testing.T) {
ctx := WithTokenScopes(context.Background(), []string{"repo"})
scopes, ok := GetTokenScopesForToken(ctx, "token-a")
assert.False(t, ok)
assert.Nil(t, scopes)
legacyScopes, legacyOK := GetTokenScopes(ctx)
assert.True(t, legacyOK)
assert.Equal(t, []string{"repo"}, legacyScopes)
}