Skip to content

Commit 004df2f

Browse files
committed
chore: rename get basic auth to encode basic auth for clarity
1 parent df56708 commit 004df2f

3 files changed

Lines changed: 6 additions & 6 deletions

File tree

internal/controller/proxy_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ func (controller *ProxyController) setHeaders(c *gin.Context, acls model.App) {
314314

315315
if acls.Response.BasicAuth.Username != "" && basicPassword != "" {
316316
tlog.App.Debug().Str("username", acls.Response.BasicAuth.Username).Msg("Setting basic auth header")
317-
c.Header("Authorization", fmt.Sprintf("Basic %s", utils.GetBasicAuth(acls.Response.BasicAuth.Username, basicPassword)))
317+
c.Header("Authorization", fmt.Sprintf("Basic %s", utils.EncodeBasicAuth(acls.Response.BasicAuth.Username, basicPassword)))
318318
}
319319
}
320320

internal/utils/security_utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func ParseSecretFile(contents string) string {
4141
return ""
4242
}
4343

44-
func GetBasicAuth(username string, password string) string {
44+
func EncodeBasicAuth(username string, password string) string {
4545
auth := username + ":" + password
4646
return base64.StdEncoding.EncodeToString([]byte(auth))
4747
}

internal/utils/security_utils_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,24 +55,24 @@ func TestParseSecretFile(t *testing.T) {
5555
assert.Equal(t, "", utils.ParseSecretFile(content))
5656
}
5757

58-
func TestGetBasicAuth(t *testing.T) {
58+
func TestEncodeBasicAuth(t *testing.T) {
5959
// Normal case
6060
username := "user"
6161
password := "pass"
6262
expected := "dXNlcjpwYXNz" // base64 of "user:pass"
63-
assert.Equal(t, expected, utils.GetBasicAuth(username, password))
63+
assert.Equal(t, expected, utils.EncodeBasicAuth(username, password))
6464

6565
// Empty username
6666
username = ""
6767
password = "pass"
6868
expected = "OnBhc3M=" // base64 of ":pass"
69-
assert.Equal(t, expected, utils.GetBasicAuth(username, password))
69+
assert.Equal(t, expected, utils.EncodeBasicAuth(username, password))
7070

7171
// Empty password
7272
username = "user"
7373
password = ""
7474
expected = "dXNlcjo=" // base64 of "user:"
75-
assert.Equal(t, expected, utils.GetBasicAuth(username, password))
75+
assert.Equal(t, expected, utils.EncodeBasicAuth(username, password))
7676
}
7777

7878
func TestFilterIP(t *testing.T) {

0 commit comments

Comments
 (0)