Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Go Httpbin
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Jira
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Container registry
Monitor
Service Desk
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
OSS
Nix
Go Httpbin
Commits
c2a9df3a
Commit
c2a9df3a
authored
Oct 16, 2016
by
Will McCutchen
Browse files
Options
Downloads
Patches
Plain Diff
Add /digest-auth/:qop/:user/:pass stub
parent
ef7fd18e
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
httpbin/handlers.go
+12
-0
12 additions, 0 deletions
httpbin/handlers.go
httpbin/handlers_test.go
+21
-0
21 additions, 0 deletions
httpbin/handlers_test.go
httpbin/httpbin.go
+2
-0
2 additions, 0 deletions
httpbin/httpbin.go
with
35 additions
and
0 deletions
httpbin/handlers.go
+
12
−
0
View file @
c2a9df3a
...
@@ -336,3 +336,15 @@ func (h *HTTPBin) HiddenBasicAuth(w http.ResponseWriter, r *http.Request) {
...
@@ -336,3 +336,15 @@ func (h *HTTPBin) HiddenBasicAuth(w http.ResponseWriter, r *http.Request) {
})
})
writeJSON
(
w
,
body
,
http
.
StatusOK
)
writeJSON
(
w
,
body
,
http
.
StatusOK
)
}
}
// DigestAuth is not yet implemented, and returns 501 Not Implemented. It
// appears that stdlib support for working with digest authentication is
// lacking, and I'm not yet ready to implement it myself.
func
(
h
*
HTTPBin
)
DigestAuth
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
parts
:=
strings
.
Split
(
r
.
URL
.
Path
,
"/"
)
if
len
(
parts
)
!=
5
{
http
.
Error
(
w
,
"Not Found"
,
http
.
StatusNotFound
)
return
}
http
.
Error
(
w
,
"Not Implemented"
,
http
.
StatusNotImplemented
)
}
This diff is collapsed.
Click to expand it.
httpbin/handlers_test.go
+
21
−
0
View file @
c2a9df3a
...
@@ -1056,3 +1056,24 @@ func TestHiddenBasicAuth(t *testing.T) {
...
@@ -1056,3 +1056,24 @@ func TestHiddenBasicAuth(t *testing.T) {
})
})
}
}
}
}
func
TestDigestAuth
(
t
*
testing
.
T
)
{
var
tests
=
[]
struct
{
url
string
status
int
}{
{
"/digest-auth/qop/user/pass"
,
http
.
StatusNotImplemented
},
{
"/digest-auth"
,
http
.
StatusNotFound
},
{
"/digest-auth/user"
,
http
.
StatusNotFound
},
{
"/digest-auth/user/pass"
,
http
.
StatusNotFound
},
{
"/digest-auth/qop/user/pass/foo"
,
http
.
StatusNotFound
},
}
for
_
,
test
:=
range
tests
{
t
.
Run
(
"ok"
+
test
.
url
,
func
(
t
*
testing
.
T
)
{
r
,
_
:=
http
.
NewRequest
(
"GET"
,
test
.
url
,
nil
)
w
:=
httptest
.
NewRecorder
()
handler
.
ServeHTTP
(
w
,
r
)
assertStatusCode
(
t
,
w
,
test
.
status
)
})
}
}
This diff is collapsed.
Click to expand it.
httpbin/httpbin.go
+
2
−
0
View file @
c2a9df3a
...
@@ -86,12 +86,14 @@ func (h *HTTPBin) Handler() http.Handler {
...
@@ -86,12 +86,14 @@ func (h *HTTPBin) Handler() http.Handler {
mux
.
HandleFunc
(
"/basic-auth/"
,
h
.
BasicAuth
)
mux
.
HandleFunc
(
"/basic-auth/"
,
h
.
BasicAuth
)
mux
.
HandleFunc
(
"/hidden-basic-auth/"
,
h
.
HiddenBasicAuth
)
mux
.
HandleFunc
(
"/hidden-basic-auth/"
,
h
.
HiddenBasicAuth
)
mux
.
HandleFunc
(
"/digest-auth/"
,
h
.
DigestAuth
)
// Make sure our ServeMux doesn't "helpfully" redirect these invalid
// Make sure our ServeMux doesn't "helpfully" redirect these invalid
// endpoints by adding a trailing slash. See the ServeMux docs for more
// endpoints by adding a trailing slash. See the ServeMux docs for more
// info: https://golang.org/pkg/net/http/#ServeMux
// info: https://golang.org/pkg/net/http/#ServeMux
mux
.
HandleFunc
(
"/absolute-redirect"
,
http
.
NotFound
)
mux
.
HandleFunc
(
"/absolute-redirect"
,
http
.
NotFound
)
mux
.
HandleFunc
(
"/basic-auth"
,
http
.
NotFound
)
mux
.
HandleFunc
(
"/basic-auth"
,
http
.
NotFound
)
mux
.
HandleFunc
(
"/digest-auth"
,
http
.
NotFound
)
mux
.
HandleFunc
(
"/hidden-basic-auth"
,
http
.
NotFound
)
mux
.
HandleFunc
(
"/hidden-basic-auth"
,
http
.
NotFound
)
mux
.
HandleFunc
(
"/redirect"
,
http
.
NotFound
)
mux
.
HandleFunc
(
"/redirect"
,
http
.
NotFound
)
mux
.
HandleFunc
(
"/relative-redirect"
,
http
.
NotFound
)
mux
.
HandleFunc
(
"/relative-redirect"
,
http
.
NotFound
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment