-
Notifications
You must be signed in to change notification settings - Fork 0
/
resource_server_test.go
87 lines (67 loc) · 2.66 KB
/
resource_server_test.go
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package go_ciba
import (
"testing"
"github.com/adisazhar123/go-ciba/test_data"
"github.com/adisazhar123/go-ciba/util"
"github.com/stretchr/testify/assert"
)
func TestResourceServer_HandleResourceRequest_ShouldReturnErrInvalidToken(t *testing.T) {
rs := &resourceServer{
accessTokenRepo: test_data.NewAccessTokenVolatileRepository(),
scopeUtil: util.ScopeUtil{},
}
invalidToken := "4C6C584A-EB31-4E11-A3E7-EADBBB573E96"
err := rs.HandleResourceRequest(&ResourceRequest{
accessToken: invalidToken,
}, "")
assert.NotNil(t, err)
assert.EqualError(t, err, util.ErrInvalidToken.Error())
}
func TestResourceServer_HandleResourceRequest_ShouldReturnErrInsufficientScope(t *testing.T) {
rs := &resourceServer{
accessTokenRepo: test_data.NewAccessTokenVolatileRepository(),
scopeUtil: util.ScopeUtil{},
}
token := "C59D9FBC-D8E4-4B8B-A95B-14F931EE1AB3"
err := rs.HandleResourceRequest(&ResourceRequest{accessToken: token}, "payment:write")
assert.NotNil(t, err)
assert.EqualError(t, err, util.ErrInsufficientScope.Error())
}
func TestResourceServer_HandleResourceRequest_ShouldReturnErrInsufficientScope2(t *testing.T) {
rs := &resourceServer{
accessTokenRepo: test_data.NewAccessTokenVolatileRepository(),
scopeUtil: util.ScopeUtil{},
}
token := test_data.AccessTokenValid.Value
err := rs.HandleResourceRequest(&ResourceRequest{accessToken: token}, "openid email profile chat:write payment:write")
assert.NotNil(t, err)
assert.EqualError(t, err, util.ErrInsufficientScope.Error())
}
func TestResourceServer_HandleResourceRequest_ShouldReturnErrInvalidTokenWhenExpired(t *testing.T) {
rs := &resourceServer{
accessTokenRepo: test_data.NewAccessTokenVolatileRepository(),
scopeUtil: util.ScopeUtil{},
}
token := test_data.AccessTokenExpired.Value
err := rs.HandleResourceRequest(&ResourceRequest{accessToken: token}, "")
assert.NotNil(t, err)
assert.EqualError(t, err, util.ErrInvalidToken.Error())
}
func TestResourceServer_HandleResourceRequest_ShouldSucceedWhenTokenIsValid(t *testing.T) {
rs := &resourceServer{
accessTokenRepo: test_data.NewAccessTokenVolatileRepository(),
scopeUtil: util.ScopeUtil{},
}
token := test_data.AccessTokenValid.Value
err := rs.HandleResourceRequest(&ResourceRequest{accessToken: token}, "")
assert.Nil(t, err)
}
func TestResourceServer_HandleResourceRequest_ShouldSucceedWhenTokenIsValid_CustomScope(t *testing.T) {
rs := &resourceServer{
accessTokenRepo: test_data.NewAccessTokenVolatileRepository(),
scopeUtil: util.ScopeUtil{},
}
token := test_data.AccessTokenValid.Value
err := rs.HandleResourceRequest(&ResourceRequest{accessToken: token}, "chat:write")
assert.Nil(t, err)
}