forked from grafana/grafana
-
Notifications
You must be signed in to change notification settings - Fork 0
/
encoding_test.go
34 lines (28 loc) · 882 Bytes
/
encoding_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package util
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestGetBasicAuthHeader_Encoding(t *testing.T) {
t.Run("generating base64 header", func(t *testing.T) {
result := GetBasicAuthHeader("grafana", "1234")
assert.Equal(t, "Basic Z3JhZmFuYToxMjM0", result)
})
t.Run("decoding basic auth header", func(t *testing.T) {
header := GetBasicAuthHeader("grafana", "1234")
username, password, err := DecodeBasicAuthHeader(header)
require.NoError(t, err)
assert.Equal(t, "grafana", username)
assert.Equal(t, "1234", password)
})
}
func TestEncodePassword(t *testing.T) {
encodedPassword, err := EncodePassword("iamgod", "pepper")
require.NoError(t, err)
assert.Equal(
t,
"e59c568621e57756495a468f47c74e07c911b037084dd464bb2ed72410970dc849cabd71b48c394faf08a5405dae53741ce9",
encodedPassword,
)
}