-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcommon_test.go
71 lines (55 loc) · 1.64 KB
/
common_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
package fibercasbinrest_test
import (
fibercasbinrest "github.com/prongbang/fiber-casbinrest"
"github.com/stretchr/testify/assert"
"testing"
)
func TestParseRolesSuccess(t *testing.T) {
// Given
expect := []string{"ADMIN", "USER"}
roles := []interface{}{"ADMIN", "USER"}
// When
actual := fibercasbinrest.ParseRoles(roles)
// Then
assert.Equal(t, actual, expect)
}
func TestGetValueSuccess(t *testing.T) {
// Given
expect := "John Doe"
token := "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiSm9obiBEb2UifQ.3fazvmF342WiHp5uhY-wkWArn-YJxq1IO7Msrtfk-OQ"
key := "name"
secret := []byte("test")
// When
actual, _ := fibercasbinrest.GetValue(token, key, secret)
// Then
assert.Equal(t, actual, expect)
}
func TestGetValueError(t *testing.T) {
// Given
expect := ""
token := "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiSm9obiBEb2UifQ.3fazvmF342WiHp5uhY-wkWArn-YJxq1IO7Msrtfk-OQ"
key := "name"
secret := []byte("invalid-secret")
// When
actual, _ := fibercasbinrest.GetValue(token, key, secret)
// Then
assert.Equal(t, actual, expect)
}
func TestVerifyTrue(t *testing.T) {
// Given
token := "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiSm9obiBEb2UifQ.3fazvmF342WiHp5uhY-wkWArn-YJxq1IO7Msrtfk-OQ"
secret := []byte("test")
// When
actual := fibercasbinrest.Verify(token, secret)
// Then
assert.Equal(t, actual, true)
}
func TestVerifyFalse(t *testing.T) {
// Given
token := "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiSm9obiBEb2UifQ.3fazvmF342WiHp5uhY-wkWArn-YJxq1IO7Msrtfk-OQ"
secret := []byte("invalid-secret")
// When
actual := fibercasbinrest.Verify(token, secret)
// Then
assert.Equal(t, actual, false)
}