-
Notifications
You must be signed in to change notification settings - Fork 209
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Missed some actual tests, added them. - Added a bunch of useless tests to increase coverage. Guilty as charged.
- Loading branch information
Showing
11 changed files
with
549 additions
and
52 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
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package defaults | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/volatiletech/authboss" | ||
) | ||
|
||
func TestSetCore(t *testing.T) { | ||
t.Parallel() | ||
|
||
config := &authboss.Config{} | ||
SetCore(config, false, false) | ||
|
||
if config.Core.Logger == nil { | ||
t.Error("logger should be set") | ||
} | ||
if config.Core.Router == nil { | ||
t.Error("router should be set") | ||
} | ||
if config.Core.ErrorHandler == nil { | ||
t.Error("error handler should be set") | ||
} | ||
if config.Core.Responder == nil { | ||
t.Error("responder should be set") | ||
} | ||
if config.Core.Redirector == nil { | ||
t.Error("redirector should be set") | ||
} | ||
if config.Core.BodyReader == nil { | ||
t.Error("bodyreader should be set") | ||
} | ||
if config.Core.Mailer == nil { | ||
t.Error("mailer should be set") | ||
} | ||
if config.Core.Logger == nil { | ||
t.Error("logger should be set") | ||
} | ||
} |
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 |
---|---|---|
|
@@ -9,7 +9,7 @@ import ( | |
"github.com/volatiletech/authboss/internal/mocks" | ||
) | ||
|
||
func TestHTTPBodyReader(t *testing.T) { | ||
func TestHTTPBodyReaderLogin(t *testing.T) { | ||
t.Parallel() | ||
|
||
h := NewHTTPBodyReader(false, false) | ||
|
@@ -48,3 +48,101 @@ func TestHTTPBodyReaderJSON(t *testing.T) { | |
t.Error("wrong password:", uv.GetPassword()) | ||
} | ||
} | ||
|
||
func TestHTTPBodyReaderConfirm(t *testing.T) { | ||
t.Parallel() | ||
|
||
h := NewHTTPBodyReader(false, false) | ||
r := mocks.Request("POST", FormValueConfirm, "token") | ||
|
||
validator, err := h.Read("confirm", r) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
||
cv := validator.(authboss.ConfirmValuer) | ||
if "token" != cv.GetToken() { | ||
t.Error("token was wrong:", cv.GetToken()) | ||
} | ||
} | ||
|
||
func TestHTTPBodyReaderRecoverStart(t *testing.T) { | ||
t.Parallel() | ||
|
||
h := NewHTTPBodyReader(false, false) | ||
r := mocks.Request("POST", FormValueEmail, "email") | ||
|
||
validator, err := h.Read("recover_start", r) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
||
rsv := validator.(authboss.RecoverStartValuer) | ||
if pid := rsv.GetPID(); pid != "email" { | ||
t.Error("token was wrong:", pid) | ||
} | ||
} | ||
|
||
func TestHTTPBodyReaderRecoverMiddle(t *testing.T) { | ||
t.Parallel() | ||
|
||
h := NewHTTPBodyReader(false, false) | ||
r := httptest.NewRequest("GET", "/?token=token", nil) | ||
|
||
validator, err := h.Read("recover_middle", r) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
||
rmv := validator.(authboss.RecoverMiddleValuer) | ||
if token := rmv.GetToken(); token != "token" { | ||
t.Error("token was wrong:", token) | ||
} | ||
} | ||
|
||
func TestHTTPBodyReaderRecoverEnd(t *testing.T) { | ||
t.Parallel() | ||
|
||
h := NewHTTPBodyReader(false, false) | ||
r := mocks.Request("POST", "token", "token", "password", "password") | ||
|
||
validator, err := h.Read("recover_end", r) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
||
rmv := validator.(authboss.RecoverEndValuer) | ||
if token := rmv.GetToken(); token != "token" { | ||
t.Error("token was wrong:", token) | ||
} | ||
if password := rmv.GetPassword(); password != "password" { | ||
t.Error("password was wrong:", password) | ||
} | ||
} | ||
|
||
func TestHTTPBodyReaderRegister(t *testing.T) { | ||
t.Parallel() | ||
|
||
h := NewHTTPBodyReader(false, false) | ||
h.Whitelist["register"] = []string{"address"} | ||
r := mocks.Request("POST", "email", "[email protected]", "password", "1234", "address", "555 go street") | ||
|
||
validator, err := h.Read("register", r) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
||
rv := validator.(authboss.UserValuer) | ||
if pid := rv.GetPID(); pid != "[email protected]" { | ||
t.Error("pid was wrong:", pid) | ||
} | ||
if password := rv.GetPassword(); password != "1234" { | ||
t.Error("password was wrong:", password) | ||
} | ||
|
||
arb := validator.(authboss.ArbitraryValuer) | ||
values := arb.GetValues() | ||
if address := values["address"]; address != "555 go street" { | ||
t.Error("address was wrong:", address) | ||
} | ||
} |
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
Oops, something went wrong.