Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
nghttp2
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
nghttp2
Commits
f72e496f
Commit
f72e496f
authored
Jan 16, 2016
by
Tatsuhiro Tsujikawa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
nghttpx: Add integration tests for Forwarded header field support
parent
41047aec
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
196 additions
and
0 deletions
+196
-0
integration-tests/nghttpx_http2_test.go
integration-tests/nghttpx_http2_test.go
+196
-0
No files found.
integration-tests/nghttpx_http2_test.go
View file @
f72e496f
...
...
@@ -8,6 +8,7 @@ import (
"io"
"io/ioutil"
"net/http"
"regexp"
"strings"
"syscall"
"testing"
...
...
@@ -123,6 +124,147 @@ func TestH2H1StripAddXff(t *testing.T) {
}
}
// TestH2H1AddForwardedObfuscated tests that server generates
// Forwarded header field with obfuscated "by" and "for" parameters.
func
TestH2H1AddForwardedObfuscated
(
t
*
testing
.
T
)
{
st
:=
newServerTester
([]
string
{
"--add-forwarded=by,for,host,proto"
},
t
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
pattern
:=
fmt
.
Sprintf
(
`by="_[^"]+";for="_[^"]+";host="127.0.0.1:%v";proto="http"`
,
serverPort
)
validFwd
:=
regexp
.
MustCompile
(
pattern
)
got
:=
r
.
Header
.
Get
(
"Forwarded"
)
if
!
validFwd
.
MatchString
(
got
)
{
t
.
Errorf
(
"Forwarded = %v; want pattern %v"
,
got
,
pattern
)
}
})
defer
st
.
Close
()
res
,
err
:=
st
.
http2
(
requestParam
{
name
:
"TestH2H1AddForwardedObfuscated"
,
})
if
err
!=
nil
{
t
.
Fatalf
(
"Error st.http2() = %v"
,
err
)
}
if
got
,
want
:=
res
.
status
,
200
;
got
!=
want
{
t
.
Errorf
(
"status: %v; want %v"
,
got
,
want
)
}
}
// TestH2H1AddForwardedByIP tests that server generates Forwarded header
// field with IP address in "by" parameter.
func
TestH2H1AddForwardedByIP
(
t
*
testing
.
T
)
{
st
:=
newServerTester
([]
string
{
"--add-forwarded=by,for,host,proto"
,
"--forwarded-by=ip"
,
"--forwarded-for=_bravo"
},
t
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
want
:=
fmt
.
Sprintf
(
`by="127.0.0.1:%v";for="_bravo";host="127.0.0.1:%v";proto="http"`
,
serverPort
,
serverPort
)
if
got
:=
r
.
Header
.
Get
(
"Forwarded"
);
got
!=
want
{
t
.
Errorf
(
"Forwarded = %v; want %v"
,
got
,
want
)
}
})
defer
st
.
Close
()
res
,
err
:=
st
.
http2
(
requestParam
{
name
:
"TestH2H1AddForwardedByIP"
,
})
if
err
!=
nil
{
t
.
Fatalf
(
"Error st.http2() = %v"
,
err
)
}
if
got
,
want
:=
res
.
status
,
200
;
got
!=
want
{
t
.
Errorf
(
"status: %v; want %v"
,
got
,
want
)
}
}
// TestH2H1AddForwardedForIP tests that server generates Forwarded header
// field with IP address in "for" parameters.
func
TestH2H1AddForwardedForIP
(
t
*
testing
.
T
)
{
st
:=
newServerTester
([]
string
{
"--add-forwarded=by,for,host,proto"
,
"--forwarded-by=_alpha"
,
"--forwarded-for=ip"
},
t
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
want
:=
fmt
.
Sprintf
(
`by="_alpha";for="127.0.0.1";host="127.0.0.1:%v";proto="http"`
,
serverPort
)
if
got
:=
r
.
Header
.
Get
(
"Forwarded"
);
got
!=
want
{
t
.
Errorf
(
"Forwarded = %v; want %v"
,
got
,
want
)
}
})
defer
st
.
Close
()
res
,
err
:=
st
.
http2
(
requestParam
{
name
:
"TestH2H1AddForwardedForIP"
,
})
if
err
!=
nil
{
t
.
Fatalf
(
"Error st.http2() = %v"
,
err
)
}
if
got
,
want
:=
res
.
status
,
200
;
got
!=
want
{
t
.
Errorf
(
"status: %v; want %v"
,
got
,
want
)
}
}
// TestH2H1AddForwardedMerge tests that server generates Forwarded
// header field with IP address in "by" and "for" parameters. The
// generated values must be appended to the existing value.
func
TestH2H1AddForwardedMerge
(
t
*
testing
.
T
)
{
st
:=
newServerTester
([]
string
{
"--add-forwarded=proto"
},
t
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
if
got
,
want
:=
r
.
Header
.
Get
(
"Forwarded"
),
`host=foo, proto="http"`
;
got
!=
want
{
t
.
Errorf
(
"Forwarded = %v; want %v"
,
got
,
want
)
}
})
defer
st
.
Close
()
res
,
err
:=
st
.
http2
(
requestParam
{
name
:
"TestH2H1AddForwardedMerge"
,
header
:
[]
hpack
.
HeaderField
{
pair
(
"forwarded"
,
"host=foo"
),
},
})
if
err
!=
nil
{
t
.
Fatalf
(
"Error st.http2() = %v"
,
err
)
}
if
got
,
want
:=
res
.
status
,
200
;
got
!=
want
{
t
.
Errorf
(
"status: %v; want %v"
,
got
,
want
)
}
}
// TestH2H1AddForwardedStrip tests that server generates Forwarded
// header field with IP address in "by" and "for" parameters. The
// generated values must not include the existing value.
func
TestH2H1AddForwardedStrip
(
t
*
testing
.
T
)
{
st
:=
newServerTester
([]
string
{
"--strip-incoming-forwarded"
,
"--add-forwarded=proto"
},
t
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
if
got
,
want
:=
r
.
Header
.
Get
(
"Forwarded"
),
`proto="http"`
;
got
!=
want
{
t
.
Errorf
(
"Forwarded = %v; want %v"
,
got
,
want
)
}
})
defer
st
.
Close
()
res
,
err
:=
st
.
http2
(
requestParam
{
name
:
"TestH2H1AddForwardedStrip"
,
header
:
[]
hpack
.
HeaderField
{
pair
(
"forwarded"
,
"host=foo"
),
},
})
if
err
!=
nil
{
t
.
Fatalf
(
"Error st.http2() = %v"
,
err
)
}
if
got
,
want
:=
res
.
status
,
200
;
got
!=
want
{
t
.
Errorf
(
"status: %v; want %v"
,
got
,
want
)
}
}
// TestH2H1AddForwardedStatic tests that server generates Forwarded
// header field with the given static obfuscated strings for "by" and
// "for" parameters.
func
TestH2H1AddForwardedStatic
(
t
*
testing
.
T
)
{
st
:=
newServerTester
([]
string
{
"--add-forwarded=by,for"
,
"--forwarded-by=_alpha"
,
"--forwarded-for=_bravo"
},
t
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
if
got
,
want
:=
r
.
Header
.
Get
(
"Forwarded"
),
`by="_alpha";for="_bravo"`
;
got
!=
want
{
t
.
Errorf
(
"Forwarded = %v; want %v"
,
got
,
want
)
}
})
defer
st
.
Close
()
res
,
err
:=
st
.
http2
(
requestParam
{
name
:
"TestH2H1AddForwardedStatic"
,
})
if
err
!=
nil
{
t
.
Fatalf
(
"Error st.http2() = %v"
,
err
)
}
if
got
,
want
:=
res
.
status
,
200
;
got
!=
want
{
t
.
Errorf
(
"status: %v; want %v"
,
got
,
want
)
}
}
// TestH2H1GenerateVia tests that server generates Via header field to and
// from backend server.
func
TestH2H1GenerateVia
(
t
*
testing
.
T
)
{
...
...
@@ -1348,6 +1490,60 @@ func TestH2H2TLSXfp(t *testing.T) {
}
}
// TestH2H2AddForwarded tests that server generates Forwarded header
// field using static obfuscated "by" and "for" parameter, and
// existing Forwarded header field.
func
TestH2H2AddForwarded
(
t
*
testing
.
T
)
{
st
:=
newServerTesterTLS
([]
string
{
"--http2-bridge"
,
"--add-forwarded=by,for,host,proto"
,
"--forwarded-by=_alpha"
,
"--forwarded-for=_bravo"
},
t
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
want
:=
fmt
.
Sprintf
(
`host=foo, by="_alpha";for="_bravo";host="127.0.0.1:%v";proto="https"`
,
serverPort
)
if
got
:=
r
.
Header
.
Get
(
"Forwarded"
);
got
!=
want
{
t
.
Errorf
(
"Forwarded = %v; want %v"
,
got
,
want
)
}
})
defer
st
.
Close
()
res
,
err
:=
st
.
http2
(
requestParam
{
name
:
"TestH2H2AddForwarded"
,
scheme
:
"https"
,
header
:
[]
hpack
.
HeaderField
{
pair
(
"forwarded"
,
"host=foo"
),
},
})
if
err
!=
nil
{
t
.
Fatalf
(
"Error st.http2() = %v"
,
err
)
}
if
got
,
want
:=
res
.
status
,
200
;
got
!=
want
{
t
.
Errorf
(
"status: %v; want %v"
,
got
,
want
)
}
}
// TestH2H2AddForwardedStrip tests that server generates Forwarded
// header field using static obfuscated "by" and "for" parameter, and
// existing Forwarded header field stripped.
func
TestH2H2AddForwardedStrip
(
t
*
testing
.
T
)
{
st
:=
newServerTesterTLS
([]
string
{
"--http2-bridge"
,
"--strip-incoming-forwarded"
,
"--add-forwarded=by,for,host,proto"
,
"--forwarded-by=_alpha"
,
"--forwarded-for=_bravo"
},
t
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
want
:=
fmt
.
Sprintf
(
`by="_alpha";for="_bravo";host="127.0.0.1:%v";proto="https"`
,
serverPort
)
if
got
:=
r
.
Header
.
Get
(
"Forwarded"
);
got
!=
want
{
t
.
Errorf
(
"Forwarded = %v; want %v"
,
got
,
want
)
}
})
defer
st
.
Close
()
res
,
err
:=
st
.
http2
(
requestParam
{
name
:
"TestH2H2AddForwardedStrip"
,
scheme
:
"https"
,
header
:
[]
hpack
.
HeaderField
{
pair
(
"forwarded"
,
"host=foo"
),
},
})
if
err
!=
nil
{
t
.
Fatalf
(
"Error st.http2() = %v"
,
err
)
}
if
got
,
want
:=
res
.
status
,
200
;
got
!=
want
{
t
.
Errorf
(
"status: %v; want %v"
,
got
,
want
)
}
}
// TestH2H2ReqPhaseReturn tests mruby request phase hook returns
// custom response.
func
TestH2H2ReqPhaseReturn
(
t
*
testing
.
T
)
{
...
...
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