Add LDAP browser flow login failure tests to supervisor_login_test.go

Also do some refactoring to share more common test setup code in
supervisor_login_test.go.
This commit is contained in:
Ryan Richard 2022-05-10 16:22:07 -07:00
parent 0b106c245e
commit aa732a41fb
5 changed files with 382 additions and 799 deletions

View File

@ -26,7 +26,7 @@ Notes:
</div> </div>
{{if .HasAlertError}} {{if .HasAlertError}}
<div class="form-field"> <div class="form-field">
<span class="alert" role="alert" aria-label="login error message">{{.AlertMessage}}</span> <span class="alert" role="alert" aria-label="login error message" id="alert">{{.AlertMessage}}</span>
</div> </div>
{{end}} {{end}}
<form action="{{.PostPath}}" method="post"> <form action="{{.PostPath}}" method="post">

View File

@ -14,7 +14,7 @@ func ExpectedLoginPageHTML(wantCSS, wantIDPName, wantPostPath, wantEncodedState,
if wantAlert != "" { if wantAlert != "" {
alertHTML = fmt.Sprintf("\n"+ alertHTML = fmt.Sprintf("\n"+
" <div class=\"form-field\">\n"+ " <div class=\"form-field\">\n"+
" <span class=\"alert\" role=\"alert\" aria-label=\"login error message\">%s</span>\n"+ " <span class=\"alert\" role=\"alert\" aria-label=\"login error message\" id=\"alert\">%s</span>\n"+
" </div>\n ", " </div>\n ",
wantAlert, wantAlert,
) )

View File

@ -50,7 +50,7 @@ import (
) )
// TestE2EFullIntegration_Browser tests a full integration scenario that combines the supervisor, concierge, and CLI. // TestE2EFullIntegration_Browser tests a full integration scenario that combines the supervisor, concierge, and CLI.
func TestE2EFullIntegration_Browser(t *testing.T) { // nolint:gocyclo func TestE2EFullIntegration_Browser(t *testing.T) {
env := testlib.IntegrationEnv(t) env := testlib.IntegrationEnv(t)
topSetupCtx, cancelFunc := context.WithTimeout(context.Background(), 5*time.Minute) topSetupCtx, cancelFunc := context.WithTimeout(context.Background(), 5*time.Minute)

File diff suppressed because it is too large Load Diff

View File

@ -188,11 +188,7 @@ func LoginToUpstreamOIDC(t *testing.T, page *agouti.Page, upstream testlib.TestO
func LoginToUpstreamLDAP(t *testing.T, page *agouti.Page, issuer, username, password string) { func LoginToUpstreamLDAP(t *testing.T, page *agouti.Page, issuer, username, password string) {
t.Helper() t.Helper()
usernameSelector := "#username" loginURLRegexp, err := regexp.Compile(`\A` + regexp.QuoteMeta(issuer+"/login") + `\?state=.+\z`)
passwordSelector := "#password"
loginButtonSelector := "#submit"
loginURLRegexp, err := regexp.Compile(`\A` + regexp.QuoteMeta(issuer+"/login") + `.+\z`)
require.NoError(t, err) require.NoError(t, err)
// Expect to be redirected to the login page. // Expect to be redirected to the login page.
@ -200,11 +196,31 @@ func LoginToUpstreamLDAP(t *testing.T, page *agouti.Page, issuer, username, pass
WaitForURL(t, page, loginURLRegexp) WaitForURL(t, page, loginURLRegexp)
// Wait for the login page to be rendered. // Wait for the login page to be rendered.
WaitForVisibleElements(t, page, usernameSelector, passwordSelector, loginButtonSelector) WaitForVisibleElements(t, page, "#username", "#password", "#submit")
// Fill in the username and password and click "submit".
SubmitUpstreamLDAPLoginForm(t, page, username, password)
}
func SubmitUpstreamLDAPLoginForm(t *testing.T, page *agouti.Page, username string, password string) {
t.Helper()
// Fill in the username and password and click "submit". // Fill in the username and password and click "submit".
t.Logf("logging in via Supervisor's upstream LDAP/AD login UI page") t.Logf("logging in via Supervisor's upstream LDAP/AD login UI page")
require.NoError(t, page.First(usernameSelector).Fill(username)) require.NoError(t, page.First("#username").Fill(username))
require.NoError(t, page.First(passwordSelector).Fill(password)) require.NoError(t, page.First("#password").Fill(password))
require.NoError(t, page.First(loginButtonSelector).Click()) require.NoError(t, page.First("#submit").Click())
}
func WaitForUpstreamLDAPLoginPageWithError(t *testing.T, page *agouti.Page, issuer string) {
t.Helper()
// Wait for redirect back to the login page again with an error.
t.Logf("waiting for redirect to back to login page with error message")
loginURLRegexp, err := regexp.Compile(`\A` + regexp.QuoteMeta(issuer+"/login") + `\?err=login_error&state=.+\z`)
require.NoError(t, err)
WaitForURL(t, page, loginURLRegexp)
// Wait for the login page to be rendered again, this time also with an error message.
WaitForVisibleElements(t, page, "#username", "#password", "#submit", "#alert")
} }