diff --git a/go.mod b/go.mod index 4b57cd5..d51e777 100644 --- a/go.mod +++ b/go.mod @@ -1,5 +1,7 @@ module github.com/dimensi0n/persona +go 1.14 + require ( github.com/jinzhu/gorm v1.9.1 github.com/jinzhu/inflection v0.0.0-20180308033659-04140366298a // indirect diff --git a/persona_test.go b/persona_test.go index 1a03402..783468e 100644 --- a/persona_test.go +++ b/persona_test.go @@ -10,7 +10,7 @@ import ( _ "github.com/jinzhu/gorm/dialects/sqlite" ) -func TestSignup(t *testing.T) { +func TestSignupWithUsername(t *testing.T) { w := httptest.NewRecorder() @@ -39,7 +39,7 @@ func TestSignup(t *testing.T) { } } -func TestLogout(t *testing.T) { +func TestLogoutWithUsername(t *testing.T) { w := httptest.NewRecorder() db, err := gorm.Open("sqlite3", "test.db") @@ -63,7 +63,60 @@ func TestLogout(t *testing.T) { } } -func TestLogin(t *testing.T) { +func TestSignupWithEmail(t *testing.T) { + + w := httptest.NewRecorder() + + db, err := gorm.Open("sqlite3", "test.db") + if err != nil { + t.Error(err) + } + defer db.Close() + + db.DropTable(&User{}) + db.DropTable(&Sessionusername{}) + + db.AutoMigrate(&User{}) + + Config(db, "email") + + user := User{Username: "Erwan", Password: HashPassword("0000"), Mail: "e@e.e"} + err = Signup(&user, user.Mail, w) + if err != nil { + t.Error(err) + } + + resp := w.Result() + if resp.Cookies()[0].Value == "" { + t.Error(errors.New("no session cookie")) + } +} + +func TestLogoutWithEmail(t *testing.T) { + w := httptest.NewRecorder() + + db, err := gorm.Open("sqlite3", "test.db") + if err != nil { + t.Error(err) + } + defer db.Close() + + Config(db, "email") + + user := User{Username: "Erwan", Password: "0000", Mail: "e@e.e"} + + err = Logout(user.Mail, w) + if err != nil { + t.Error(err) + } + + resp := w.Result() + if resp.Cookies()[0].Value != "" { + t.Error(errors.New("cookie was not deleted")) + } +} + +func TestLoginWithUsername(t *testing.T) { w := httptest.NewRecorder() @@ -88,6 +141,31 @@ func TestLogin(t *testing.T) { } } +func TestLoginWithEmail(t *testing.T) { + + w := httptest.NewRecorder() + + db, err := gorm.Open("sqlite3", "test.db") + if err != nil { + t.Error(err) + } + defer db.Close() + + Config(db, "email") + + user := User{Username: "Erwan", Password: "0000", Mail: "e@e.e"} + + err = Login(user.Mail, user.Password, w) + if err != nil { + t.Error(err) + } + + resp := w.Result() + if resp.Cookies()[0].Value == "" { + t.Error(errors.New("no session cookie")) + } +} + func TestCurrentUser(t *testing.T) { w := httptest.NewRecorder()