summaryrefslogtreecommitdiff
path: root/internal/handlers/handler_verify_test.go
diff options
context:
space:
mode:
authorAmir Zarrinkafsh <nightah@me.com>2020-11-16 22:22:16 +1100
committerGitHub <noreply@github.com>2020-11-16 22:22:16 +1100
commit50df9495207c159582afa8f8724f6c4acb2d243f (patch)
tree269109f94394cf96c8be5dc0f9335be1227c935c /internal/handlers/handler_verify_test.go
parent8e32a4b65f90d95ffd7bb4056082257392c06a9d (diff)
[BUGFIX] Prevent crash when email has not been set (#1466)
* [BUGFIX] Prevent crash when email has not been set https://github.com/authelia/authelia/commit/a83ccd71887cb843adce10fe14d630fbf3ac9bec introduced a regression where if a misconfigured deployment presented an empty emails array setting `Remote-*` headers would fail. If the emails array is empty we now set the `Remote-Email` header to an empty string. * Add additional case for unit tests
Diffstat (limited to 'internal/handlers/handler_verify_test.go')
-rw-r--r--internal/handlers/handler_verify_test.go20
1 files changed, 20 insertions, 0 deletions
diff --git a/internal/handlers/handler_verify_test.go b/internal/handlers/handler_verify_test.go
index 06cfb744a..88e9a0d56 100644
--- a/internal/handlers/handler_verify_test.go
+++ b/internal/handlers/handler_verify_test.go
@@ -413,6 +413,26 @@ func TestShouldVerifyFailingDetailsFetchingInBasicAuth(t *testing.T) {
"https://test.example.com", actualStatus, expStatus)
}
+func TestShouldNotCrashOnEmptyEmail(t *testing.T) {
+ mock := mocks.NewMockAutheliaCtx(t)
+ defer mock.Close()
+
+ userSession := mock.Ctx.GetSession()
+ userSession.Username = testUsername
+ userSession.Emails = nil
+ userSession.AuthenticationLevel = authentication.OneFactor
+ mock.Ctx.SaveSession(userSession) //nolint:errcheck // TODO: Legacy code, consider refactoring time permitting.
+
+ mock.Ctx.Request.Header.Set("X-Original-URL", "https://bypass.example.com")
+
+ VerifyGet(verifyGetCfg)(mock.Ctx)
+
+ expStatus, actualStatus := 200, mock.Ctx.Response.StatusCode()
+ assert.Equal(t, expStatus, actualStatus, "URL=%s -> StatusCode=%d != ExpectedStatusCode=%d",
+ "https://bypass.example.com", actualStatus, expStatus)
+ assert.Equal(t, []byte(nil), mock.Ctx.Response.Header.Peek("Remote-Email"))
+}
+
type Pair struct {
URL string
Username string