1
0
mirror of https://github.com/oauth2-proxy/oauth2-proxy.git synced 2024-11-24 08:52:25 +02:00

Add tests for split host port

This commit is contained in:
Joel Speed 2021-06-05 13:24:04 +01:00
parent 273ab1f591
commit bd2fa9d7d8
No known key found for this signature in database
GPG Key ID: 6E80578D6751DEFB

View File

@ -99,4 +99,45 @@ var _ = Describe("Validator suite", func() {
Entry("Partial Subdomain", "evilbar.foo", false),
)
})
Context("SplitHostPort", func() {
type splitHostPortTableInput struct {
hostport string
expectedHost string
expectedPort string
}
DescribeTable("Should split the host and port",
func(in splitHostPortTableInput) {
host, port := splitHostPort(in.hostport)
Expect(host).To(Equal(in.expectedHost))
Expect(port).To(Equal(in.expectedPort))
},
Entry("when no port is specified", splitHostPortTableInput{
hostport: "foo.bar",
expectedHost: "foo.bar",
expectedPort: "",
}),
Entry("with a valid port specified", splitHostPortTableInput{
hostport: "foo.bar:8080",
expectedHost: "foo.bar",
expectedPort: "8080",
}),
Entry("with an invalid port specified", splitHostPortTableInput{
hostport: "foo.bar:808a",
expectedHost: "foo.bar:808a",
expectedPort: "",
}),
Entry("with a wildcard port specified", splitHostPortTableInput{
hostport: "foo.bar:*",
expectedHost: "foo.bar",
expectedPort: "*",
}),
Entry("when the host is specified with brackets", splitHostPortTableInput{
hostport: "[foo.bar]",
expectedHost: "foo.bar",
expectedPort: "",
}),
)
})
})