2017-10-18 03:01:26 +02:00
|
|
|
package auth
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"testing"
|
2019-07-31 00:40:26 +02:00
|
|
|
|
|
|
|
"github.com/zclconf/go-cty/cty"
|
2017-10-18 03:01:26 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestHostCredentialsToken(t *testing.T) {
|
|
|
|
creds := HostCredentialsToken("foo-bar")
|
|
|
|
|
2019-07-31 00:40:26 +02:00
|
|
|
{
|
|
|
|
req := &http.Request{}
|
|
|
|
creds.PrepareRequest(req)
|
|
|
|
authStr := req.Header.Get("authorization")
|
|
|
|
if got, want := authStr, "Bearer foo-bar"; got != want {
|
|
|
|
t.Errorf("wrong Authorization header value %q; want %q", got, want)
|
|
|
|
}
|
|
|
|
}
|
2017-10-18 03:01:26 +02:00
|
|
|
|
2019-07-31 00:40:26 +02:00
|
|
|
{
|
|
|
|
got := creds.ToStore()
|
|
|
|
want := cty.ObjectVal(map[string]cty.Value{
|
|
|
|
"token": cty.StringVal("foo-bar"),
|
|
|
|
})
|
|
|
|
if !want.RawEquals(got) {
|
|
|
|
t.Errorf("wrong storable object value\ngot: %#v\nwant: %#v", got, want)
|
|
|
|
}
|
2017-10-18 03:01:26 +02:00
|
|
|
}
|
|
|
|
}
|