-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add uri authority encode utils 191 (#192)
* Add a util functions to encode authority strictly following RFC 3986. Fixes #191 * update signature vars to use "raw" prefix
- Loading branch information
Showing
4 changed files
with
145 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
go1.22.0 | ||
go1.22.4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,7 @@ type authorityTest struct { | |
} | ||
|
||
func (a *authoritySuite) TestAuthority() { | ||
tests := []*authorityTest{ | ||
tests := []authorityTest{ | ||
{ | ||
authorityString: "", | ||
host: "", | ||
|
@@ -308,6 +308,80 @@ func (a *authoritySuite) TestAuthority() { | |
} | ||
} | ||
|
||
type encodeAuthorityTest struct { | ||
rawAuthority string | ||
expectedEncoded string | ||
hasError bool | ||
errMessage string | ||
message string | ||
} | ||
|
||
func (a *authoritySuite) TestEncodeAuthority() { | ||
tests := []encodeAuthorityTest{ | ||
{ | ||
rawAuthority: "domain.com\\[email protected]:22", | ||
expectedEncoded: "domain.com%[email protected]:22", | ||
hasError: false, | ||
errMessage: "", | ||
message: "basic encoding", | ||
}, | ||
{ | ||
rawAuthority: "example.com:80", | ||
expectedEncoded: "example.com:80", | ||
hasError: false, | ||
errMessage: "", | ||
message: "no user info", | ||
}, | ||
{ | ||
rawAuthority: "user:[email protected]", | ||
expectedEncoded: "user:[email protected]", | ||
hasError: false, | ||
errMessage: "", | ||
message: "username and password", | ||
}, | ||
{ | ||
rawAuthority: "[email protected]:22", | ||
expectedEncoded: "[email protected]:22", | ||
hasError: false, | ||
errMessage: "", | ||
message: "exclamation point in username (remains unencoded)", | ||
}, | ||
{ | ||
rawAuthority: "[email protected]", | ||
expectedEncoded: "[email protected]", | ||
hasError: false, | ||
errMessage: "", | ||
message: "username only", | ||
}, | ||
{ | ||
rawAuthority: "host.com:8080", | ||
expectedEncoded: "host.com:8080", | ||
hasError: false, | ||
errMessage: "", | ||
message: "host and port only", | ||
}, | ||
{ | ||
rawAuthority: "@host.com", | ||
expectedEncoded: "host.com", | ||
hasError: false, | ||
errMessage: "", | ||
message: "empty user info", | ||
}, | ||
} | ||
|
||
for _, t := range tests { | ||
a.Run(t.message, func() { | ||
actual, err := EncodeAuthority(t.rawAuthority) | ||
if t.hasError { | ||
a.ErrorContains(err, t.errMessage, t.message) | ||
} else { | ||
a.NoError(err, t.message) | ||
a.Equal(t.expectedEncoded, actual, t.message) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestAuthority(t *testing.T) { | ||
suite.Run(t, new(authoritySuite)) | ||
} |