summaryrefslogtreecommitdiffstats
path: root/services/auth/additional_scopes_test.go
blob: 9ab4e6e61fce9c89d97c6aa52bd97b168e7df762 (plain)
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 auth

import (
	"testing"

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

func TestGrantAdditionalScopes(t *testing.T) {
	tests := []struct {
		grantScopes    string
		expectedScopes string
	}{
		{"openid profile email", ""},
		{"openid profile email groups", ""},
		{"openid profile email all", "all"},
		{"openid profile email read:user all", "read:user,all"},
		{"openid profile email groups read:user", "read:user"},
		{"read:user read:repository", "read:user,read:repository"},
		{"read:user write:issue public-only", "read:user,write:issue,public-only"},
		{"openid profile email read:user", "read:user"},
		{"read:invalid_scope", ""},
		{"read:invalid_scope,write:scope_invalid,just-plain-wrong", ""},
	}

	for _, test := range tests {
		t.Run(test.grantScopes, func(t *testing.T) {
			result := grantAdditionalScopes(test.grantScopes)
			assert.Equal(t, test.expectedScopes, result)
		})
	}
}