-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontroller_test.go
More file actions
43 lines (32 loc) · 1.29 KB
/
controller_test.go
File metadata and controls
43 lines (32 loc) · 1.29 KB
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
package main
import . "gopkg.in/check.v1"
//func Test(t *testing.T) { TestingT(t) }
type CtrlSuite struct{}
var _ = Suite(&CtrlSuite{})
func CreateMockUser() {
u, _ := NewUser(firstName, lastName, email, password, scope)
u.SaveUser()
}
func (s *CtrlSuite) TestValidLogin(c *C) {
// valid credentials should get a valid Token
CreateMockUser()
_, err := Login(email, password)
c.Assert(err, IsNil)
}
func (s *CtrlSuite) TestInvalidLogin(c *C) {
//invalid credentials should get an error
_, err := Login(email, "wrongpassword")
c.Assert(err, NotNil)
}
func (s *CtrlSuite) TestIsAuthenticatedValidToken(c *C) {
//checks whether token is valid
validToken := "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE0NDMyNzQyODUsImlzcyI6Ind3dy5hc3ZpbnMuY29tLmJyIiwic2NvcGUiOiJwYXRpZW50Iiwic3ViIjoiam9obmRvZUBleGFtcGxlLmNvbSJ9.XYbHd0sNHnzkRlZwiTwSIdhedYKE5eKsnuJJ-D1Tnv8"
_, err := IsAuthenticated(validToken)
c.Assert(err, IsNil)
}
func (s *CtrlSuite) TestIsAuthenticatedInvalidToken(c *C) {
//checks whether token is valid
validToken := "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE0NDMyNzQyODUsImlzcyI6Ind3dy5hc3ZpbnMuY29tLmJyIiwic2NvcGUiOiJwYXRpZW50Iiwic3ViIjoiam9obmRvZUBleGFtcGxlLmNvbSJ9.XYbHd0sNHnzkRlZwiTwSIdhedYKE5fKsnuJJ-D1Tnv8"
_, err := IsAuthenticated(validToken)
c.Assert(err, NotNil)
}