1
// Copyright 2015 Canonical Ltd.
2
// Licensed under the LGPLv3, see LICENSE file for details.
7
"launchpad.net/gocheck"
11
// When NormalizeURL() is passed a simple URL, it will make no changes
13
func (suite *USSOTestSuite) TestNormalizeURLReturnsBasicURL(c *gocheck.C) {
14
output, err := NormalizeURL("http://example.com/path")
15
c.Check(err, gocheck.Equals, nil)
16
c.Check(output, gocheck.Equals, "http://example.com/path")
19
// NormalizeURL() strips the ":80" from http:// URLs that contain it.
20
func (suite *USSOTestSuite) TestNormalizeURLStripsStandardHTTPPort(
22
output, err := NormalizeURL("http://example.com:80/path")
23
c.Check(err, gocheck.Equals, nil)
24
c.Check(output, gocheck.Equals, "http://example.com/path")
27
// NormalizeURL() strips the ":443" from https:// URLs that contain it.
28
func (suite *USSOTestSuite) TestNormalizeURLStripsStandardHTTPSPort(
30
output, err := NormalizeURL("https://example.com:443/path")
31
c.Check(err, gocheck.Equals, nil)
32
c.Check(output, gocheck.Equals, "https://example.com/path")
35
// NormalizeURL() does not remove non-standard ports from the URL.
36
func (suite *USSOTestSuite) TestNormalizeURLLeavesNonstandardPort(
38
output, err := NormalizeURL("http://example.com:8080/")
39
c.Check(err, gocheck.Equals, nil)
40
c.Check(output, gocheck.Equals, "http://example.com:8080/")
43
// NormalizeURL() strips the query string from URLs.
44
func (suite *USSOTestSuite) TestNormalizeURLStripsParameters(c *gocheck.C) {
45
output, err := NormalizeURL("http://example.com/path?query=value¶m=arg")
46
c.Check(err, gocheck.Equals, nil)
47
c.Check(output, gocheck.Equals, "http://example.com/path")
50
// NormalizeParameters() takes a url.Values instance and returns an
51
// encoded key=value string containing the parameters in that instance.
52
func (suite *USSOTestSuite) TestNormalizeParametersReturnsParameters(
54
output, err := NormalizeParameters(url.Values{"param": []string{"value"}})
55
c.Check(err, gocheck.Equals, nil)
56
c.Check(output, gocheck.Equals, "param=value")
59
// NormalizeParameters() encodes multiple key/value parameters as a
61
func (suite *USSOTestSuite) TestNormalizeParametersConcatenatesParameters(
63
output, err := NormalizeParameters(
64
url.Values{"a": []string{"1"}, "b": []string{"2"}})
65
c.Check(err, gocheck.Equals, nil)
66
c.Check(output, gocheck.Matches, "(a=1&b=2)")
69
// NormalizeParameters() escapes the parameters correctly when encoding
70
// them as a query string.
71
func (suite *USSOTestSuite) TestNormalizeParametersEscapesParameters(
73
output, err := NormalizeParameters(url.Values{"a&b": []string{"1"}})
74
c.Check(err, gocheck.Equals, nil)
75
c.Check(output, gocheck.Equals, "a%26b=1")
78
// If oauth_signature appears in the parameters passed to
79
// NormalizeParameters(), it is omitted in the returned string as it does not
80
// have to be included in the computation of the new oauth_signature.
81
func (suite *USSOTestSuite) TestNormalizeParametersOmitsOAuthSignature(
85
"oauth_signature": []string{"foobarsplatszot"},
88
output, err := NormalizeParameters(params)
89
c.Check(err, gocheck.Equals, nil)
90
c.Check(output, gocheck.Matches, "(a=1&z=26)")
93
var escapeTests = map[string]string{
352
func (suite *USSOTestSuite) TestEscape(c *gocheck.C) {
353
for in, expected := range escapeTests {
354
c.Assert(escape(in), gocheck.Equals, expected)