| 1 | // Copyright 2015 Matthew Holt and The Caddy Authors |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package caddyauthscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth`/ |
| 16 | |
| 17 | import ( |
| 18 | "contextscip-go gomod github.com/golang/go/src go1.25.1 context/" |
| 19 | "errorsscip-go gomod github.com/golang/go/src go1.25.1 errors/" |
| 20 | "net/httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/" |
| 21 | "net/http/httptestscip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/" |
| 22 | "testingscip-go gomod github.com/golang/go/src go1.25.1 testing/" |
| 23 | |
| 24 | "go.uber.org/zapscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/" |
| 25 | |
| 26 | "github.com/caddyserver/caddy/v2scip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/" |
| 27 | "github.com/caddyserver/caddy/v2/modules/caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/" |
| 28 | ) |
| 29 | |
| 30 | func TestAuthenticationRejectedUserSetsCandidatePlaceholdersscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth`/TestAuthenticationRejectedUserSetsCandidatePlaceholders().(t *testingscip-go gomod github.com/golang/go/src go1.25.1 testing/.Tscip-go gomod github.com/golang/go/src go1.25.1 testing/T#) { |
| 31 | auth := Authenticationscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth`/Authentication#{ |
| 32 | Providersscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth`/Authentication#Providers.: map[string]Authenticatorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth`/Authenticator#{ |
| 33 | "test": staticAuthenticatorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth`/staticAuthenticator#{ |
| 34 | userscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth`/staticAuthenticator#user.: Userscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth`/User#{ |
| 35 | IDscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth`/User#ID.: "alice", |
| 36 | Metadatascip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth`/User#Metadata.: map[string]string{ |
| 37 | "role": "admin", |
| 38 | }, |
| 39 | }, |
| 40 | }, |
| 41 | }, |
| 42 | loggerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth`/Authentication#logger.: zapscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/.NewNopscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/NewNop().(), |
| 43 | } |
| 44 | req, repl := newRequestWithReplacerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth`/newRequestWithReplacer().() |
| 45 | nextCalled := false |
| 46 | |
| 47 | err := auth.ServeHTTPscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth`/Authentication#ServeHTTP().(httptestscip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/.NewRecorderscip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/NewRecorder().(), req, caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.HandlerFuncscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/HandlerFunc#(func(httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.ResponseWriterscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/ResponseWriter#, *httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.Requestscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#) error { |
| 48 | nextCalled = true |
| 49 | return nil |
| 50 | })) |
| 51 | if err == nil { |
| 52 | t.Fatalscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Fatal().("expected authentication error") |
| 53 | } |
| 54 | var handlerErr caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.HandlerErrorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/HandlerError# |
| 55 | if !errorsscip-go gomod github.com/golang/go/src go1.25.1 errors/.Asscip-go gomod github.com/golang/go/src go1.25.1 errors/As().(err, &handlerErr) { |
| 56 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Fatalf().("expected HandlerError, got %T", err) |
| 57 | } |
| 58 | if handlerErr.StatusCodescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/HandlerError#StatusCode. != httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.StatusUnauthorizedscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/StatusUnauthorized. { |
| 59 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Fatalf().("expected status %d, got %d", httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.StatusUnauthorizedscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/StatusUnauthorized., handlerErr.StatusCodescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/HandlerError#StatusCode.) |
| 60 | } |
| 61 | if nextCalled { |
| 62 | t.Fatalscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Fatal().("next handler was called for rejected authentication") |
| 63 | } |
| 64 | |
| 65 | assertPlaceholderscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth`/assertPlaceholder().(t, repl, "http.auth.candidate.id", "alice") |
| 66 | assertPlaceholderscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth`/assertPlaceholder().(t, repl, "http.auth.candidate.role", "admin") |
| 67 | assertPlaceholderAbsentscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth`/assertPlaceholderAbsent().(t, repl, "http.auth.user.id") |
| 68 | assertPlaceholderAbsentscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth`/assertPlaceholderAbsent().(t, repl, "http.auth.user.role") |
| 69 | } |
| 70 | |
| 71 | func TestAuthenticationSuccessfulUserSetsUserPlaceholdersOnlyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth`/TestAuthenticationSuccessfulUserSetsUserPlaceholdersOnly().(t *testingscip-go gomod github.com/golang/go/src go1.25.1 testing/.Tscip-go gomod github.com/golang/go/src go1.25.1 testing/T#) { |
| 72 | auth := Authenticationscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth`/Authentication#{ |
| 73 | Providersscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth`/Authentication#Providers.: map[string]Authenticatorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth`/Authenticator#{ |
| 74 | "test": staticAuthenticatorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth`/staticAuthenticator#{ |
| 75 | userscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth`/staticAuthenticator#user.: Userscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth`/User#{ |
| 76 | IDscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth`/User#ID.: "alice", |
| 77 | Metadatascip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth`/User#Metadata.: map[string]string{ |
| 78 | "role": "admin", |
| 79 | }, |
| 80 | }, |
| 81 | authedscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth`/staticAuthenticator#authed.: true, |
| 82 | }, |
| 83 | }, |
| 84 | loggerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth`/Authentication#logger.: zapscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/.NewNopscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/NewNop().(), |
| 85 | } |
| 86 | req, repl := newRequestWithReplacerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth`/newRequestWithReplacer().() |
| 87 | nextCalled := false |
| 88 | |
| 89 | err := auth.ServeHTTPscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth`/Authentication#ServeHTTP().(httptestscip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/.NewRecorderscip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/NewRecorder().(), req, caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.HandlerFuncscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/HandlerFunc#(func(httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.ResponseWriterscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/ResponseWriter#, *httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.Requestscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#) error { |
| 90 | nextCalled = true |
| 91 | return nil |
| 92 | })) |
| 93 | if err != nil { |
| 94 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Fatalf().("expected no authentication error, got %v", err) |
| 95 | } |
| 96 | if !nextCalled { |
| 97 | t.Fatalscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Fatal().("next handler was not called for successful authentication") |
| 98 | } |
| 99 | |
| 100 | assertPlaceholderscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth`/assertPlaceholder().(t, repl, "http.auth.user.id", "alice") |
| 101 | assertPlaceholderscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth`/assertPlaceholder().(t, repl, "http.auth.user.role", "admin") |
| 102 | assertPlaceholderAbsentscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth`/assertPlaceholderAbsent().(t, repl, "http.auth.candidate.id") |
| 103 | assertPlaceholderAbsentscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth`/assertPlaceholderAbsent().(t, repl, "http.auth.candidate.role") |
| 104 | } |
| 105 | |
| 106 | func TestAuthenticationSuccessfulProviderDoesNotExposeEarlierCandidatescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth`/TestAuthenticationSuccessfulProviderDoesNotExposeEarlierCandidate().(t *testingscip-go gomod github.com/golang/go/src go1.25.1 testing/.Tscip-go gomod github.com/golang/go/src go1.25.1 testing/T#) { |
| 107 | auth := Authenticationscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth`/Authentication#{ |
| 108 | Providersscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth`/Authentication#Providers.: map[string]Authenticatorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth`/Authenticator#{ |
| 109 | "first": staticAuthenticatorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth`/staticAuthenticator#{ |
| 110 | userscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth`/staticAuthenticator#user.: Userscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth`/User#{ |
| 111 | IDscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth`/User#ID.: "rejected", |
| 112 | Metadatascip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth`/User#Metadata.: map[string]string{ |
| 113 | "role": "guest", |
| 114 | }, |
| 115 | }, |
| 116 | }, |
| 117 | "second": staticAuthenticatorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth`/staticAuthenticator#{ |
| 118 | userscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth`/staticAuthenticator#user.: Userscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth`/User#{ |
| 119 | IDscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth`/User#ID.: "accepted", |
| 120 | Metadatascip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth`/User#Metadata.: map[string]string{ |
| 121 | "role": "admin", |
| 122 | }, |
| 123 | }, |
| 124 | authedscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth`/staticAuthenticator#authed.: true, |
| 125 | }, |
| 126 | }, |
| 127 | loggerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth`/Authentication#logger.: zapscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/.NewNopscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/NewNop().(), |
| 128 | } |
| 129 | req, repl := newRequestWithReplacerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth`/newRequestWithReplacer().() |
| 130 | |
| 131 | err := auth.ServeHTTPscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth`/Authentication#ServeHTTP().(httptestscip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/.NewRecorderscip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/NewRecorder().(), req, caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.HandlerFuncscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/HandlerFunc#(func(httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.ResponseWriterscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/ResponseWriter#, *httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.Requestscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#) error { |
| 132 | return nil |
| 133 | })) |
| 134 | if err != nil { |
| 135 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Fatalf().("expected no authentication error, got %v", err) |
| 136 | } |
| 137 | |
| 138 | assertPlaceholderscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth`/assertPlaceholder().(t, repl, "http.auth.user.id", "accepted") |
| 139 | assertPlaceholderscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth`/assertPlaceholder().(t, repl, "http.auth.user.role", "admin") |
| 140 | assertPlaceholderAbsentscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth`/assertPlaceholderAbsent().(t, repl, "http.auth.candidate.id") |
| 141 | assertPlaceholderAbsentscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth`/assertPlaceholderAbsent().(t, repl, "http.auth.candidate.role") |
| 142 | } |
| 143 | |
| 144 | func TestAuthenticationRejectedEmptyUserDoesNotSetCandidatePlaceholdersscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth`/TestAuthenticationRejectedEmptyUserDoesNotSetCandidatePlaceholders().(t *testingscip-go gomod github.com/golang/go/src go1.25.1 testing/.Tscip-go gomod github.com/golang/go/src go1.25.1 testing/T#) { |
| 145 | auth := Authenticationscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth`/Authentication#{ |
| 146 | Providersscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth`/Authentication#Providers.: map[string]Authenticatorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth`/Authenticator#{ |
| 147 | "test": staticAuthenticatorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth`/staticAuthenticator#{}, |
| 148 | }, |
| 149 | loggerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth`/Authentication#logger.: zapscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/.NewNopscip-go gomod go.uber.org/zap v1.28.0 `go.uber.org/zap`/NewNop().(), |
| 150 | } |
| 151 | req, repl := newRequestWithReplacerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth`/newRequestWithReplacer().() |
| 152 | |
| 153 | err := auth.ServeHTTPscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth`/Authentication#ServeHTTP().(httptestscip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/.NewRecorderscip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/NewRecorder().(), req, caddyhttpscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/.HandlerFuncscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp`/HandlerFunc#(func(httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.ResponseWriterscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/ResponseWriter#, *httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.Requestscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#) error { |
| 154 | t.Fatalscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Fatal().("next handler was called for rejected authentication") |
| 155 | return nil |
| 156 | })) |
| 157 | if err == nil { |
| 158 | t.Fatalscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Fatal().("expected authentication error") |
| 159 | } |
| 160 | |
| 161 | assertPlaceholderAbsentscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth`/assertPlaceholderAbsent().(t, repl, "http.auth.candidate.id") |
| 162 | } |
| 163 | |
| 164 | func newRequestWithReplacerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth`/newRequestWithReplacer().() (*httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.Requestscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#, *caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.Replacerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Replacer#) { |
| 165 | req := httptestscip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/.NewRequestscip-go gomod github.com/golang/go/src go1.25.1 `net/http/httptest`/NewRequest().(httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.MethodGetscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/MethodGet., "/", nil) |
| 166 | repl := caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.NewReplacerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/NewReplacer().() |
| 167 | ctx := contextscip-go gomod github.com/golang/go/src go1.25.1 context/.WithValuescip-go gomod github.com/golang/go/src go1.25.1 context/WithValue().(req.Contextscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#Context().(), caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.ReplacerCtxKeyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/ReplacerCtxKey., repl) |
| 168 | return req.WithContextscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#WithContext().(ctx), repl |
| 169 | } |
| 170 | |
| 171 | func assertPlaceholderscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth`/assertPlaceholder().(t *testingscip-go gomod github.com/golang/go/src go1.25.1 testing/.Tscip-go gomod github.com/golang/go/src go1.25.1 testing/T#, repl *caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.Replacerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Replacer#, key, expected string) { |
| 172 | t.Helperscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Helper().() |
| 173 | actual, ok := repl.GetStringscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Replacer#GetString().(key) |
| 174 | if !ok { |
| 175 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Fatalf().("expected placeholder %q to be set", key) |
| 176 | } |
| 177 | if actual != expected { |
| 178 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Fatalf().("expected placeholder %q to be %q, got %q", key, expected, actual) |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | func assertPlaceholderAbsentscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth`/assertPlaceholderAbsent().(t *testingscip-go gomod github.com/golang/go/src go1.25.1 testing/.Tscip-go gomod github.com/golang/go/src go1.25.1 testing/T#, repl *caddyscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/.Replacerscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Replacer#, key string) { |
| 183 | t.Helperscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Helper().() |
| 184 | if actual, ok := repl.GetStringscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2`/Replacer#GetString().(key); ok { |
| 185 | t.Fatalfscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Fatalf().("expected placeholder %q to be absent, got %q", key, actual) |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | type staticAuthenticatorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth`/staticAuthenticator# struct { |
| 190 | userscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth`/staticAuthenticator#user. Userscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth`/User# |
| 191 | authedscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth`/staticAuthenticator#authed. bool |
| 192 | errscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth`/staticAuthenticator#err. error |
| 193 | } |
| 194 | |
| 195 | func (a staticAuthenticatorscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth`/staticAuthenticator#) Authenticatescip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth`/staticAuthenticator#Authenticate().(httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.ResponseWriterscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/ResponseWriter#, *httpscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/.Requestscip-go gomod github.com/golang/go/src go1.25.1 `net/http`/Request#) (Userscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth`/User#, bool, error) { |
| 196 | return a.userscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth`/staticAuthenticator#user., a.authedscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth`/staticAuthenticator#authed., a.errscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/caddyauth`/staticAuthenticator#err. |
| 197 | } |