Skip to content

Commit

Permalink
final fixes
Browse files Browse the repository at this point in the history
* fix auth test
* fix notices test and parallelize
* cleanup unused input lookup
  • Loading branch information
cryptix committed Mar 26, 2021
1 parent 09fcd57 commit f96b916
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 41 deletions.
21 changes: 0 additions & 21 deletions web/handlers/auth/withssb.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,27 +234,6 @@ func (h WithSSBHandler) decideMethod(w http.ResponseWriter, req *http.Request) {
}
}

// input either an alias or a feed reference
// it is set by the landing form if non of the params are present
if input := queryVals.Get("input"); input != "" {
// assume ssb id first
var err error
cid, err = refs.ParseFeedRef(input)
if err != nil {
// try input as an alias
aliasEntry, err := h.aliasesdb.Resolve(req.Context(), input)
if err != nil {
h.render.Error(w, req, http.StatusBadRequest, err)
return
}
cid = &aliasEntry.Feed
alias = aliasEntry.Name
}

// update cid for server-initiated
queryVals.Set("cid", cid.Ref())
}

// ?cid=CID&cc=CC does client-initiated http-auth
if cc := queryVals.Get("cc"); cc != "" && cid != nil {
err := h.clientInitiated(w, req, *cid)
Expand Down
26 changes: 10 additions & 16 deletions web/handlers/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,14 @@ func TestLoginForm(t *testing.T) {

a, r := assert.New(t), require.New(t)

ts.AliasesDB.ResolveReturns(roomdb.Alias{}, roomdb.ErrNotFound)

url, err := ts.Router.Get(router.AuthLogin).URL()
url, err := ts.Router.Get(router.AuthFallbackLogin).URL()
r.Nil(err)
html, resp := ts.Client.GetHTML(url.String())
a.Equal(http.StatusOK, resp.Code, "wrong HTTP status code")

webassert.Localized(t, html, []webassert.LocalizedElement{
{"title", "AuthTitle"},
{"#welcome", "AuthWelcome"},
{"#describe-withssb", "AuthWithSSBStart"},
{"#describe-password", "AuthFallbackWelcome"},
{"#welcome", "AuthFallbackWelcome"},
})
}

Expand All @@ -73,9 +69,7 @@ func TestFallbackAuth(t *testing.T) {
jar, err := cookiejar.New(nil)
r.NoError(err)

ts.AliasesDB.ResolveReturns(roomdb.Alias{}, roomdb.ErrNotFound)

signInFormURL, err := ts.Router.Get(router.AuthLogin).URL()
signInFormURL, err := ts.Router.Get(router.AuthFallbackLogin).URL()
r.Nil(err)
signInFormURL.Host = "localhost"
signInFormURL.Scheme = "https"
Expand Down Expand Up @@ -108,7 +102,7 @@ func TestFallbackAuth(t *testing.T) {
}
ts.AuthFallbackDB.CheckReturns(int64(23), nil)

signInURL, err := ts.Router.Get(router.AuthFallbackLogin).URL()
signInURL, err := ts.Router.Get(router.AuthFallbackFinalize).URL()
r.Nil(err)

signInURL.Host = "localhost"
Expand Down Expand Up @@ -205,7 +199,7 @@ func TestAuthWithSSBClientInitNotConnected(t *testing.T) {

urlTo := web.NewURLTo(ts.Router)

signInStartURL := urlTo(router.AuthLogin,
signInStartURL := urlTo(router.AuthWithSSBLogin,
"cid", client.Feed.Ref(),
"cc", cc,
)
Expand Down Expand Up @@ -236,7 +230,7 @@ func TestAuthWithSSBClientInitNotAllowed(t *testing.T) {

urlTo := web.NewURLTo(ts.Router)

signInStartURL := urlTo(router.AuthLogin,
signInStartURL := urlTo(router.AuthWithSSBLogin,
"cid", client.Feed.Ref(),
"cc", cc,
)
Expand Down Expand Up @@ -318,7 +312,7 @@ func TestAuthWithSSBClientInitHasClient(t *testing.T) {

// prepare the url
urlTo := web.NewURLTo(ts.Router)
signInStartURL := urlTo(router.AuthLogin,
signInStartURL := urlTo(router.AuthWithSSBLogin,
"cid", client.Feed.Ref(),
"cc", cc,
)
Expand Down Expand Up @@ -401,7 +395,7 @@ func TestAuthWithSSBServerInitHappyPath(t *testing.T) {

// prepare the url
urlTo := web.NewURLTo(ts.Router)
signInStartURL := urlTo(router.AuthLogin,
signInStartURL := urlTo(router.AuthWithSSBLogin,
"cid", client.Feed.Ref(),
)
r.NotNil(signInStartURL)
Expand All @@ -413,7 +407,7 @@ func TestAuthWithSSBServerInitHappyPath(t *testing.T) {

webassert.Localized(t, html, []webassert.LocalizedElement{
{"title", "AuthWithSSBTitle"},
{"#welcome", "AuthWithSSBServerStart"},
{"#welcome", "AuthWithSSBWelcome"},
})

jsFile, has := html.Find("script").Attr("src")
Expand Down Expand Up @@ -527,7 +521,7 @@ func TestAuthWithSSBServerInitWrongSolution(t *testing.T) {

// prepare the url
urlTo := web.NewURLTo(ts.Router)
signInStartURL := urlTo(router.AuthLogin,
signInStartURL := urlTo(router.AuthWithSSBLogin,
"cid", client.Feed.Ref(),
)
r.NotNil(signInStartURL)
Expand Down
4 changes: 2 additions & 2 deletions web/handlers/notices_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func TestNoticesEditButtonVisible(t *testing.T) {

// when dealing with cookies we also need to have an Host and URL-Scheme
// for the jar to save and load them correctly
formEndpoint := urlTo(router.AuthLogin)
formEndpoint := urlTo(router.AuthFallbackLogin)
r.NotNil(formEndpoint)
formEndpoint.Host = "localhost"
formEndpoint.Scheme = "https"
Expand Down Expand Up @@ -128,7 +128,7 @@ func TestNoticesEditButtonVisible(t *testing.T) {
ts.AuthFallbackDB.CheckReturns(testUser.ID, nil)
ts.MembersDB.GetByIDReturns(testUser, nil)

postEndpoint, err := ts.Router.Get(router.AuthFallbackLogin).URL()
postEndpoint, err := ts.Router.Get(router.AuthFallbackFinalize).URL()
r.Nil(err)
postEndpoint.Host = "localhost"
postEndpoint.Scheme = "https"
Expand Down
1 change: 1 addition & 0 deletions web/handlers/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ type testSession struct {
var testI18N = justTheKeys()

func setup(t *testing.T) *testSession {
t.Parallel()
var ts testSession

testRepoPath := filepath.Join("testrun", t.Name())
Expand Down
2 changes: 1 addition & 1 deletion web/templates/auth/fallback_sign_in.tmpl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{ define "title" }}{{i18n "AuthTitle"}}{{ end }}
{{ define "content" }}
<div class="flex flex-col justify-center items-center self-center max-w-lg">
<span class="text-center mt-8">{{i18n "AuthFallbackWelcome"}}</span>
<span id="welcome" class="text-center mt-8">{{i18n "AuthFallbackWelcome"}}</span>

<form
id="password-fallback"
Expand Down
2 changes: 1 addition & 1 deletion web/templates/auth/withssb_server_start.tmpl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{ define "title" }}{{i18n "AuthWithSSBTitle"}}{{ end }}
{{ define "content" }}
<div class="flex flex-col justify-center items-center self-center max-w-lg">
<span class="text-center mt-8">{{i18n "AuthWithSSBWelcome"}}</span>
<span id="welcome" class="text-center mt-8">{{i18n "AuthWithSSBWelcome"}}</span>

<a
id="start-auth-uri"
Expand Down

0 comments on commit f96b916

Please sign in to comment.