Skip to content

Commit

Permalink
adding an extra auth test to check computeSharedKey
Browse files Browse the repository at this point in the history
```
=== RUN   TestComputeSharedKey
--- PASS: TestComputeSharedKey (0.00s)
    authorizer_shared_key_lite_test.go:87: [DEBUG] Test "No Path"
    authorizer_shared_key_lite_test.go:87: [DEBUG] Test "With Path"
PASS
```
  • Loading branch information
tombuildsstuff committed Aug 21, 2019
1 parent 3b7f0ae commit 3a43d34
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions azurerm/internal/authorizers/authorizer_shared_key_lite_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package authorizers

import (
"net/http"
"testing"
)

Expand Down Expand Up @@ -34,3 +35,69 @@ func TestBuildCanonicalizedStringForSharedKeyLite(t *testing.T) {
}
}
}

func TestComputeSharedKey(t *testing.T) {
testData := []struct {
name string
accountName string
method string
url string
headers map[string]string
expected string
}{
{
name: "No Path",
accountName: "unlikely23exst2acct23wi",
method: "GET",
url: "https://unlikely23exst2acct23wi.queue.core.windows.net?comp=properties&restype=service",
headers: map[string]string{
"Content-Type": "application/xml; charset=utf-8",
"X-Ms-Date": "Wed, 21 Aug 2019 11:00:25 GMT",
"X-Ms-Version": "2018-11-09",
},
expected: `GET
application/xml; charset=utf-8
x-ms-date:Wed, 21 Aug 2019 11:00:25 GMT
x-ms-version:2018-11-09
/unlikely23exst2acct23wi?comp=properties`,
},
{
name: "With Path",
accountName: "unlikely23exst2accti1t0",
method: "GET",
url: "https://unlikely23exst2accti1t0.queue.core.windows.net/?comp=properties&restype=service",
headers: map[string]string{
"Content-Type": "application/xml; charset=utf-8",
"X-Ms-Date": "Wed, 21 Aug 2019 11:53:48 GMT",
"X-Ms-Version": "2018-11-09",
},
expected: `GET
application/xml; charset=utf-8
x-ms-date:Wed, 21 Aug 2019 11:53:48 GMT
x-ms-version:2018-11-09
/unlikely23exst2accti1t0/?comp=properties`,
},
}

for _, v := range testData {
t.Logf("[DEBUG] Test %q", v.name)

headers := http.Header{}
for hn, hv := range v.headers {
headers.Add(hn, hv)
}

actual, err := computeSharedKeyLite(v.method, v.url, v.accountName, headers)
if err != nil {
t.Fatalf("Error computing shared key: %s", err)
}

if *actual != v.expected {
t.Fatalf("Expected %q but got %q", v.expected, *actual)
}
}
}

0 comments on commit 3a43d34

Please sign in to comment.