2015-03-02 02:58:35 -06:00
|
|
|
package util
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2020-08-13 04:10:48 -05:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
2015-03-02 02:58:35 -06:00
|
|
|
)
|
|
|
|
|
2020-08-13 04:10:48 -05:00
|
|
|
func TestGetBasicAuthHeader_Encoding(t *testing.T) {
|
|
|
|
t.Run("generating base64 header", func(t *testing.T) {
|
2015-03-02 02:58:35 -06:00
|
|
|
result := GetBasicAuthHeader("grafana", "1234")
|
2020-08-13 04:10:48 -05:00
|
|
|
assert.Equal(t, "Basic Z3JhZmFuYToxMjM0", result)
|
2015-03-02 02:58:35 -06:00
|
|
|
})
|
2015-06-30 02:37:52 -05:00
|
|
|
|
2020-08-13 04:10:48 -05:00
|
|
|
t.Run("decoding basic auth header", func(t *testing.T) {
|
2015-06-30 02:37:52 -05:00
|
|
|
header := GetBasicAuthHeader("grafana", "1234")
|
|
|
|
username, password, err := DecodeBasicAuthHeader(header)
|
2020-08-13 04:10:48 -05:00
|
|
|
require.NoError(t, err)
|
2015-06-30 02:37:52 -05:00
|
|
|
|
2020-08-13 04:10:48 -05:00
|
|
|
assert.Equal(t, "grafana", username)
|
|
|
|
assert.Equal(t, "1234", password)
|
2015-06-30 02:37:52 -05:00
|
|
|
})
|
2020-08-13 04:10:48 -05:00
|
|
|
}
|
2015-06-30 02:37:52 -05:00
|
|
|
|
2020-08-13 04:10:48 -05:00
|
|
|
func TestEncodePassword(t *testing.T) {
|
|
|
|
encodedPassword, err := EncodePassword("iamgod", "pepper")
|
|
|
|
require.NoError(t, err)
|
|
|
|
assert.Equal(
|
|
|
|
t,
|
|
|
|
"e59c568621e57756495a468f47c74e07c911b037084dd464bb2ed72410970dc849cabd71b48c394faf08a5405dae53741ce9",
|
|
|
|
encodedPassword,
|
|
|
|
)
|
2015-03-02 02:58:35 -06:00
|
|
|
}
|