forked from apexskier/httpauth
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
64 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,10 @@ var ( | |
func init() { | ||
os.Remove(file) | ||
b = NewGobFileAuthBackend(file) | ||
a = NewAuthorizer(b, []byte("secret-key")) | ||
roles := make(map[string]Role) | ||
roles["user"] = 40 | ||
roles["admin"] = 80 | ||
a, _ = NewAuthorizer(b, []byte("testkey"), "user", roles) | ||
t, _ := time.Parse("Mon, 02 Jan 2006 15:04:05 MST", "Mon, 07 Apr 2014 21:47:54 UTC") | ||
authCookie = http.Cookie{ | ||
Name: "auth", | ||
|
@@ -30,21 +33,29 @@ func init() { | |
} | ||
|
||
func TestNewAuthorizer(t *testing.T) { | ||
a = NewAuthorizer(b, []byte("testkey")) | ||
roles := make(map[string]Role) | ||
roles["user"] = 40 | ||
roles["admin"] = 80 | ||
_, err := NewAuthorizer(b, []byte("testkey"), "user", roles) | ||
if err != nil { | ||
t.Fatalf(err.Error()) | ||
} | ||
} | ||
|
||
func TestRegister(t *testing.T) { | ||
rw := httptest.NewRecorder() | ||
req, _ := http.NewRequest("POST", "/", nil) | ||
err := a.Register(rw, req, "username", "password", "[email protected]") | ||
newUser := UserData{Username:"username", Email:"[email protected]"} | ||
err := a.Register(rw, req, newUser, "password") | ||
if rw.Code != http.StatusOK { | ||
t.Fatalf("Register: Wrong status code: %v", rw.Code) | ||
} | ||
if err != nil { | ||
t.Fatalf("Register: error %v", err) | ||
} | ||
|
||
err = a.Register(rw, req, "username", "password", "[email protected]") | ||
newUser2 := UserData{Username:"username", Email:"[email protected]"} | ||
err = a.Register(rw, req, newUser2, "password") | ||
if rw.Code != http.StatusOK { | ||
t.Fatalf("Register: Wrong status code: %v", rw.Code) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters