File: queuesasuri_test.go

package info (click to toggle)
golang-github-azure-azure-sdk-for-go 68.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 556,256 kB
  • sloc: javascript: 196; sh: 96; makefile: 7
file content (110 lines) | stat: -rw-r--r-- 3,179 bytes parent folder | download
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package storage

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

import (
	"net/url"
	"time"

	chk "gopkg.in/check.v1"
)

type QueueSASURISuite struct{}

var _ = chk.Suite(&QueueSASURISuite{})

var queueOldAPIVer = "2013-08-15"
var queueNewerAPIVer = "2015-04-05"

func (s *QueueSASURISuite) TestGetQueueSASURI(c *chk.C) {
	api, err := NewClient("foo", dummyMiniStorageKey, DefaultBaseURL, queueOldAPIVer, true)
	c.Assert(err, chk.IsNil)
	cli := api.GetQueueService()
	q := cli.GetQueueReference("name")

	expectedParts := url.URL{
		Scheme: "https",
		Host:   "foo.queue.core.windows.net",
		Path:   "name",
		RawQuery: url.Values{
			"sv":  {oldAPIVer},
			"sig": {"dYZ+elcEz3ZXEnTDKR5+RCrMzk0L7/ATWsemNzb36VM="},
			"sp":  {"p"},
			"se":  {"0001-01-01T00:00:00Z"},
		}.Encode()}

	options := QueueSASOptions{}
	options.Process = true
	options.Expiry = time.Time{}

	u, err := q.GetSASURI(options)
	c.Assert(err, chk.IsNil)
	sasParts, err := url.Parse(u)
	c.Assert(err, chk.IsNil)
	c.Assert(expectedParts.String(), chk.Equals, sasParts.String())
	c.Assert(expectedParts.Query(), chk.DeepEquals, sasParts.Query())
}

func (s *QueueSASURISuite) TestGetQueueSASURIWithSignedIPValidAPIVersionPassed(c *chk.C) {
	api, err := NewClient("foo", dummyMiniStorageKey, DefaultBaseURL, queueNewerAPIVer, true)
	c.Assert(err, chk.IsNil)
	cli := api.GetQueueService()
	q := cli.GetQueueReference("name")

	expectedParts := url.URL{
		Scheme: "https",
		Host:   "foo.queue.core.windows.net",
		Path:   "/name",
		RawQuery: url.Values{
			"sv":  {newerAPIVer},
			"sig": {"8uvfE93HdYxQ3xvt/CUN3S7sYEl1LcuHBC0oYoGDnfw="},
			"sip": {"127.0.0.1"},
			"sp":  {"p"},
			"se":  {"0001-01-01T00:00:00Z"},
			"spr": {"https,http"},
		}.Encode()}

	options := QueueSASOptions{}
	options.Process = true
	options.Expiry = time.Time{}
	options.IP = "127.0.0.1"

	u, err := q.GetSASURI(options)
	c.Assert(err, chk.IsNil)
	sasParts, err := url.Parse(u)
	c.Assert(err, chk.IsNil)
	c.Assert(sasParts.Query(), chk.DeepEquals, expectedParts.Query())
}

// Trying to use SignedIP but using an older version of the API.
// Should ignore the signedIP and just use what the older version requires.
func (s *QueueSASURISuite) TestGetQueueSASURIWithSignedIPUsingOldAPIVersion(c *chk.C) {
	api, err := NewClient("foo", dummyMiniStorageKey, DefaultBaseURL, oldAPIVer, true)
	c.Assert(err, chk.IsNil)
	cli := api.GetQueueService()
	q := cli.GetQueueReference("name")

	expectedParts := url.URL{
		Scheme: "https",
		Host:   "foo.queue.core.windows.net",
		Path:   "/name",
		RawQuery: url.Values{
			"sv":  {oldAPIVer},
			"sig": {"dYZ+elcEz3ZXEnTDKR5+RCrMzk0L7/ATWsemNzb36VM="},
			"sp":  {"p"},
			"se":  {"0001-01-01T00:00:00Z"},
		}.Encode()}

	options := QueueSASOptions{}
	options.Process = true
	options.Expiry = time.Time{}
	options.IP = "127.0.0.1"

	u, err := q.GetSASURI(options)
	c.Assert(err, chk.IsNil)
	sasParts, err := url.Parse(u)
	c.Assert(err, chk.IsNil)
	c.Assert(expectedParts.String(), chk.Equals, sasParts.String())
	c.Assert(expectedParts.Query(), chk.DeepEquals, sasParts.Query())
}