Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
Mirrored from https://github.com/Slazee/caddy.git
Synced Nov 12, 17:00 UTC
caddyauth: Rename `basicauth` to `basic_auth` (#6092)
Francis Lavoie committed
Feb 12, 2024 at 12:34 UTC
f9e11158bc139294804cba99e9fea408f1fb00d6
3 files changed
+14
-7
caddyconfig/caddyfile/parse_test.go
+4
-4
@@ -801,7 +801,7 @@ func TestImportedFilesIgnoreNonDirectiveImportTokens(t *testing.T) {
801
fileName := writeStringToTempFileOrDie(t, `
802
http://example.com {
803
# This isn't an import directive, it's just an arg with value 'import'
804
- basicauth / import password
804
+ basic_auth / import password
805
}
806
`)
807
// Parse the root file that imports the other one.
@@ -812,12 +812,12 @@ func TestImportedFilesIgnoreNonDirectiveImportTokens(t *testing.T) {
812
}
813
auth := blocks[0].Segments[0]
814
line := auth[0].Text + " " + auth[1].Text + " " + auth[2].Text + " " + auth[3].Text
815
- if line != "basicauth / import password" {
815
+ if line != "basic_auth / import password" {
816
// Previously, it would be changed to:
817
- // basicauth / import /path/to/test/dir/password
817
+ // basic_auth / import /path/to/test/dir/password
818
// referencing a file that (probably) doesn't exist and changing the
819
// password!
820
- t.Errorf("Expected basicauth tokens to be 'basicauth / import password' but got %#q", line)
820
+ t.Errorf("Expected basic_auth tokens to be 'basic_auth / import password' but got %#q", line)
821
}
822
}
823
caddyconfig/httpcaddyfile/directives.go
+2
-1
@@ -58,7 +58,8 @@ var directiveOrder = []string{
58
"try_files",
59
60
// middleware handlers; some wrap responses
61
- "basicauth",
61
+ "basicauth", // TODO: deprecated, renamed to basic_auth
62
+ "basic_auth",
63
"forward_auth",
64
"request_header",
65
"encode",
modules/caddyhttp/caddyauth/caddyfile.go
+8
-2
@@ -22,12 +22,13 @@ import (
22
)
23
24
func init() {
25
- httpcaddyfile.RegisterHandlerDirective("basicauth", parseCaddyfile)
25
+ httpcaddyfile.RegisterHandlerDirective("basicauth", parseCaddyfile) // deprecated
26
+ httpcaddyfile.RegisterHandlerDirective("basic_auth", parseCaddyfile)
27
}
28
29
// parseCaddyfile sets up the handler from Caddyfile tokens. Syntax:
30
//
30
-// basicauth [<matcher>] [<hash_algorithm> [<realm>]] {
31
+// basic_auth [<matcher>] [<hash_algorithm> [<realm>]] {
32
// <username> <hashed_password_base64> [<salt_base64>]
33
// ...
34
// }
@@ -36,6 +37,11 @@ func init() {
37
func parseCaddyfile(h httpcaddyfile.Helper) (caddyhttp.MiddlewareHandler, error) {
38
h.Next() // consume directive name
39
40
+ // "basicauth" is deprecated, replaced by "basic_auth"
41
+ if h.Val() == "basicauth" {
42
+ caddy.Log().Named("config.adapter.caddyfile").Warn("the 'basicauth' directive is deprecated, please use 'basic_auth' instead!")
43
+ }
44
+
45
var ba HTTPBasicAuth
46
ba.HashCache = new(Cache)
47