|
|
|
|
@ -52,9 +52,12 @@ func TestGenerateURI_Basic(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
p.config = getTestConfig()
|
|
|
|
|
|
|
|
|
|
uri := p.generateURI()
|
|
|
|
|
uri, err := p.generateURI()
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("had error: %s", err)
|
|
|
|
|
}
|
|
|
|
|
expected_uri := "vi://me:notpassword@myhost/mydc/host/mycluster"
|
|
|
|
|
if uri != expected_uri {
|
|
|
|
|
if uri.String() != expected_uri {
|
|
|
|
|
t.Fatalf("URI did not match. Recieved: %s. Expected: %s", uri, expected_uri)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -68,17 +71,17 @@ func TestGenerateURI_PasswordEscapes(t *testing.T) {
|
|
|
|
|
cases := []escapeCases{
|
|
|
|
|
{`this has spaces`, `this%20has%20spaces`},
|
|
|
|
|
{`exclaimation_!`, `exclaimation_%21`},
|
|
|
|
|
{`hash_#_dollar_$`, `hash_%23_dollar_%24`},
|
|
|
|
|
{`ampersand_&awesome`, `ampersand_%26awesome`},
|
|
|
|
|
{`hash_#_dollar_$`, `hash_%23_dollar_$`},
|
|
|
|
|
{`ampersand_&awesome`, `ampersand_&awesome`},
|
|
|
|
|
{`single_quote_'_and_another_'`, `single_quote_%27_and_another_%27`},
|
|
|
|
|
{`open_paren_(_close_paren_)`, `open_paren_%28_close_paren_%29`},
|
|
|
|
|
{`asterisk_*_plus_+`, `asterisk_%2A_plus_%2B`},
|
|
|
|
|
{`comma_,slash_/`, `comma_%2Cslash_%2F`},
|
|
|
|
|
{`colon_:semicolon_;`, `colon_%3Asemicolon_%3B`},
|
|
|
|
|
{`equal_=question_?`, `equal_%3Dquestion_%3F`},
|
|
|
|
|
{`asterisk_*_plus_+`, `asterisk_%2A_plus_+`},
|
|
|
|
|
{`comma_,slash_/`, `comma_,slash_%2F`},
|
|
|
|
|
{`colon_:semicolon_;`, `colon_%3Asemicolon_;`},
|
|
|
|
|
{`equal_=question_?`, `equal_=question_%3F`},
|
|
|
|
|
{`at_@`, `at_%40`},
|
|
|
|
|
{`open_bracket_[closed_bracket]`, `open_bracket_%5Bclosed_bracket%5D`},
|
|
|
|
|
{`user:password with $paces@host/name.foo`, `user%3Apassword%20with%20%24paces%40host%2Fname.foo`},
|
|
|
|
|
{`user:password with $paces@host/name.foo`, `user%3Apassword%20with%20$paces%40host%2Fname.foo`},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, escapeCase := range cases {
|
|
|
|
|
@ -87,42 +90,14 @@ func TestGenerateURI_PasswordEscapes(t *testing.T) {
|
|
|
|
|
p.config = getTestConfig()
|
|
|
|
|
p.config.Password = escapeCase.Input
|
|
|
|
|
|
|
|
|
|
uri := p.generateURI()
|
|
|
|
|
uri, err := p.generateURI()
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("had error: %s", err)
|
|
|
|
|
}
|
|
|
|
|
expected_uri := fmt.Sprintf("vi://me:%s@myhost/mydc/host/mycluster", escapeCase.Expected)
|
|
|
|
|
|
|
|
|
|
if uri != expected_uri {
|
|
|
|
|
if uri.String() != expected_uri {
|
|
|
|
|
t.Fatalf("URI did not match. Recieved: %s. Expected: %s", uri, expected_uri)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestEscaping(t *testing.T) {
|
|
|
|
|
type escapeCases struct {
|
|
|
|
|
Input string
|
|
|
|
|
Expected string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cases := []escapeCases{
|
|
|
|
|
{`this has spaces`, `this%20has%20spaces`},
|
|
|
|
|
{`exclaimation_!`, `exclaimation_%21`},
|
|
|
|
|
{`hash_#_dollar_$`, `hash_%23_dollar_%24`},
|
|
|
|
|
{`ampersand_&awesome`, `ampersand_%26awesome`},
|
|
|
|
|
{`single_quote_'_and_another_'`, `single_quote_%27_and_another_%27`},
|
|
|
|
|
{`open_paren_(_close_paren_)`, `open_paren_%28_close_paren_%29`},
|
|
|
|
|
{`asterisk_*_plus_+`, `asterisk_%2A_plus_%2B`},
|
|
|
|
|
{`comma_,slash_/`, `comma_%2Cslash_%2F`},
|
|
|
|
|
{`colon_:semicolon_;`, `colon_%3Asemicolon_%3B`},
|
|
|
|
|
{`equal_=question_?`, `equal_%3Dquestion_%3F`},
|
|
|
|
|
{`at_@`, `at_%40`},
|
|
|
|
|
{`open_bracket_[closed_bracket]`, `open_bracket_%5Bclosed_bracket%5D`},
|
|
|
|
|
{`user:password with $paces@host/name.foo`, `user%3Apassword%20with%20%24paces%40host%2Fname.foo`},
|
|
|
|
|
}
|
|
|
|
|
for _, escapeCase := range cases {
|
|
|
|
|
received := escapeWithSpaces(escapeCase.Input)
|
|
|
|
|
|
|
|
|
|
if escapeCase.Expected != received {
|
|
|
|
|
t.Errorf("Error escaping URL; expected %s got %s", escapeCase.Expected, received)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|