forked from hashicorp/go-azure-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoken_test.go
More file actions
29 lines (23 loc) · 708 Bytes
/
token_test.go
File metadata and controls
29 lines (23 loc) · 708 Bytes
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
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package auth_test
import (
"context"
"net/http"
"regexp"
"testing"
"github.com/hashicorp/go-azure-sdk/sdk/auth"
"github.com/hashicorp/go-azure-sdk/sdk/internal/test"
)
func TestSetAuthHeader(t *testing.T) {
req := &http.Request{}
authorizer := &test.TestAuthorizer{}
err := auth.SetAuthHeader(context.Background(), req, authorizer)
if err != nil {
t.Fatalf("received error: %+v", err)
}
expected := regexp.MustCompile("^Bearer [a-zA-Z0-9_-]+[.][a-zA-Z0-9_-]+[.][a-zA-Z0-9_-]+")
if val := req.Header.Get("Authorization"); !expected.MatchString(val) {
t.Fatalf("Authorization header mismatch, received: %q", val)
}
}