Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
ae132f62
Unverified
Commit
ae132f62
authored
May 17, 2019
by
Kubernetes Prow Robot
Committed by
GitHub
May 17, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #77978 from ahg-g/ahg-host-redirect
Added a unit test to verify that host header is preserved after probe…
parents
a7f13bca
ef2e5bb8
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
50 additions
and
0 deletions
+50
-0
http_test.go
pkg/probe/http/http_test.go
+50
-0
No files found.
pkg/probe/http/http_test.go
View file @
ae132f62
...
@@ -314,3 +314,53 @@ func TestHTTPProbeChecker_NonLocalRedirects(t *testing.T) {
...
@@ -314,3 +314,53 @@ func TestHTTPProbeChecker_NonLocalRedirects(t *testing.T) {
})
})
}
}
}
}
func
TestHTTPProbeChecker_HostHeaderPreservedAfterRedirect
(
t
*
testing
.
T
)
{
successHostHeader
:=
"www.success.com"
failHostHeader
:=
"www.fail.com"
handler
:=
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
switch
r
.
URL
.
Path
{
case
"/redirect"
:
http
.
Redirect
(
w
,
r
,
"/success"
,
http
.
StatusFound
)
case
"/success"
:
if
r
.
Host
==
successHostHeader
{
w
.
WriteHeader
(
http
.
StatusOK
)
}
else
{
http
.
Error
(
w
,
""
,
http
.
StatusBadRequest
)
}
default
:
http
.
Error
(
w
,
""
,
http
.
StatusInternalServerError
)
}
})
server
:=
httptest
.
NewServer
(
handler
)
defer
server
.
Close
()
testCases
:=
map
[
string
]
struct
{
hostHeader
string
expectedResult
probe
.
Result
}{
"success"
:
{
successHostHeader
,
probe
.
Success
},
"fail"
:
{
failHostHeader
,
probe
.
Failure
},
}
for
desc
,
test
:=
range
testCases
{
headers
:=
http
.
Header
{}
headers
.
Add
(
"Host"
,
test
.
hostHeader
)
t
.
Run
(
desc
+
"local"
,
func
(
t
*
testing
.
T
)
{
followNonLocalRedirects
:=
false
prober
:=
New
(
followNonLocalRedirects
)
target
,
err
:=
url
.
Parse
(
server
.
URL
+
"/redirect"
)
require
.
NoError
(
t
,
err
)
result
,
_
,
_
:=
prober
.
Probe
(
target
,
headers
,
wait
.
ForeverTestTimeout
)
assert
.
Equal
(
t
,
test
.
expectedResult
,
result
)
})
t
.
Run
(
desc
+
"nonlocal"
,
func
(
t
*
testing
.
T
)
{
followNonLocalRedirects
:=
true
prober
:=
New
(
followNonLocalRedirects
)
target
,
err
:=
url
.
Parse
(
server
.
URL
+
"/redirect"
)
require
.
NoError
(
t
,
err
)
result
,
_
,
_
:=
prober
.
Probe
(
target
,
headers
,
wait
.
ForeverTestTimeout
)
assert
.
Equal
(
t
,
test
.
expectedResult
,
result
)
})
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment