mirror of
https://github.com/steveiliop56/tinyauth.git
synced 2026-05-08 05:18:11 +00:00
chore: rename get basic auth to encode basic auth for clarity
This commit is contained in:
@@ -314,7 +314,7 @@ func (controller *ProxyController) setHeaders(c *gin.Context, acls model.App) {
|
|||||||
|
|
||||||
if acls.Response.BasicAuth.Username != "" && basicPassword != "" {
|
if acls.Response.BasicAuth.Username != "" && basicPassword != "" {
|
||||||
tlog.App.Debug().Str("username", acls.Response.BasicAuth.Username).Msg("Setting basic auth header")
|
tlog.App.Debug().Str("username", acls.Response.BasicAuth.Username).Msg("Setting basic auth header")
|
||||||
c.Header("Authorization", fmt.Sprintf("Basic %s", utils.GetBasicAuth(acls.Response.BasicAuth.Username, basicPassword)))
|
c.Header("Authorization", fmt.Sprintf("Basic %s", utils.EncodeBasicAuth(acls.Response.BasicAuth.Username, basicPassword)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ func ParseSecretFile(contents string) string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetBasicAuth(username string, password string) string {
|
func EncodeBasicAuth(username string, password string) string {
|
||||||
auth := username + ":" + password
|
auth := username + ":" + password
|
||||||
return base64.StdEncoding.EncodeToString([]byte(auth))
|
return base64.StdEncoding.EncodeToString([]byte(auth))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,24 +55,24 @@ func TestParseSecretFile(t *testing.T) {
|
|||||||
assert.Equal(t, "", utils.ParseSecretFile(content))
|
assert.Equal(t, "", utils.ParseSecretFile(content))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetBasicAuth(t *testing.T) {
|
func TestEncodeBasicAuth(t *testing.T) {
|
||||||
// Normal case
|
// Normal case
|
||||||
username := "user"
|
username := "user"
|
||||||
password := "pass"
|
password := "pass"
|
||||||
expected := "dXNlcjpwYXNz" // base64 of "user:pass"
|
expected := "dXNlcjpwYXNz" // base64 of "user:pass"
|
||||||
assert.Equal(t, expected, utils.GetBasicAuth(username, password))
|
assert.Equal(t, expected, utils.EncodeBasicAuth(username, password))
|
||||||
|
|
||||||
// Empty username
|
// Empty username
|
||||||
username = ""
|
username = ""
|
||||||
password = "pass"
|
password = "pass"
|
||||||
expected = "OnBhc3M=" // base64 of ":pass"
|
expected = "OnBhc3M=" // base64 of ":pass"
|
||||||
assert.Equal(t, expected, utils.GetBasicAuth(username, password))
|
assert.Equal(t, expected, utils.EncodeBasicAuth(username, password))
|
||||||
|
|
||||||
// Empty password
|
// Empty password
|
||||||
username = "user"
|
username = "user"
|
||||||
password = ""
|
password = ""
|
||||||
expected = "dXNlcjo=" // base64 of "user:"
|
expected = "dXNlcjo=" // base64 of "user:"
|
||||||
assert.Equal(t, expected, utils.GetBasicAuth(username, password))
|
assert.Equal(t, expected, utils.EncodeBasicAuth(username, password))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFilterIP(t *testing.T) {
|
func TestFilterIP(t *testing.T) {
|
||||||
|
|||||||
Reference in New Issue
Block a user