Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3
Commits
9956630e
Commit
9956630e
authored
Nov 15, 2018
by
Dr Ian Preston
Committed by
Steven Allen
Nov 28, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add more p2p http proxy tests
License: MIT Signed-off-by:
Ian Preston
<
ianopolous@protonmail.com
>
parent
3b2ce4a8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
15 deletions
+36
-15
core/corehttp/proxy_test.go
core/corehttp/proxy_test.go
+36
-15
No files found.
core/corehttp/proxy_test.go
View file @
9956630e
...
...
@@ -6,29 +6,50 @@ import (
"testing"
"github.com/ipfs/go-ipfs/thirdparty/assert"
protocol
"gx/ipfs/QmZNkThpqfVXs9GNbexPrfBbXSLNYeKrE7jwFM2oqHbyqN/go-libp2p-protocol"
)
type
TestCase
struct
{
urlprefix
string
target
string
name
string
path
string
}
var
validtestCases
=
[]
TestCase
{
{
"http://localhost:5001"
,
"QmT8JtU54XSmC38xSb1XHFSMm775VuTeajg7LWWWTAwzxT"
,
"/http"
,
"path/to/index.txt"
},
{
"http://localhost:5001"
,
"QmT8JtU54XSmC38xSb1XHFSMm775VuTeajg7LWWWTAwzxT"
,
"/x/custom/http"
,
"path/to/index.txt"
},
{
"http://localhost:5001"
,
"QmT8JtU54XSmC38xSb1XHFSMm775VuTeajg7LWWWTAwzxT"
,
"/x/custom/http"
,
"http/path/to/index.txt"
},
}
func
TestParseRequest
(
t
*
testing
.
T
)
{
url
:=
"http://localhost:5001/p2p/QmT8JtU54XSmC38xSb1XHFSMm775VuTeajg7LWWWTAwzxT/http/path/to/index.txt"
req
,
_
:=
http
.
NewRequest
(
"GET"
,
url
,
strings
.
NewReader
(
""
))
for
_
,
tc
:=
range
validtestCases
{
url
:=
tc
.
urlprefix
+
"/p2p/"
+
tc
.
target
+
tc
.
name
+
"/"
+
tc
.
path
req
,
_
:=
http
.
NewRequest
(
"GET"
,
url
,
strings
.
NewReader
(
""
))
parsed
,
err
:=
parseRequest
(
req
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
parsed
,
err
:=
parseRequest
(
req
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
assert
.
True
(
parsed
.
httpPath
==
tc
.
path
,
t
,
"proxy request path"
)
assert
.
True
(
parsed
.
name
==
protocol
.
ID
(
tc
.
name
),
t
,
"proxy request name"
)
assert
.
True
(
parsed
.
target
==
tc
.
target
,
t
,
"proxy request peer-id"
)
}
assert
.
True
(
parsed
.
httpPath
==
"path/to/index.txt"
,
t
,
"proxy request path"
)
assert
.
True
(
parsed
.
name
==
"/http"
,
t
,
"proxy request name"
)
assert
.
True
(
parsed
.
target
==
"QmT8JtU54XSmC38xSb1XHFSMm775VuTeajg7LWWWTAwzxT"
,
t
,
"proxy request peer-id"
)
}
var
invalidtestCases
=
[]
string
{
"http://localhost:5001/p2p/http/foobar"
,
}
func
TestParseRequestInvalidPath
(
t
*
testing
.
T
)
{
url
:=
"http://localhost:5001/p2p/http/foobar"
req
,
_
:=
http
.
NewRequest
(
"GET"
,
url
,
strings
.
NewReader
(
""
))
for
_
,
tc
:=
range
invalidtestCases
{
url
:=
tc
req
,
_
:=
http
.
NewRequest
(
"GET"
,
url
,
strings
.
NewReader
(
""
))
_
,
err
:=
parseRequest
(
req
)
if
err
==
nil
{
t
.
Fail
()
_
,
err
:=
parseRequest
(
req
)
if
err
==
nil
{
t
.
Fail
()
}
}
assert
.
True
(
err
.
Error
()
==
"Invalid request path '/p2p/http/foobar'"
,
t
,
"fails with invalid path"
)
}
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