-
Notifications
You must be signed in to change notification settings - Fork 620
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #302: Add read-only mode for UI
This patch adds an access mode for the ui endpoint which allows to disable some or most endpoints with a simple config option. Fixes #302
- Loading branch information
1 parent
1759b37
commit 9d97241
Showing
9 changed files
with
132 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package admin | ||
|
||
import ( | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
) | ||
|
||
func TestAdminServerAccess(t *testing.T) { | ||
type test struct { | ||
uri string | ||
code int | ||
} | ||
|
||
testAccess := func(access string, tests []test) { | ||
srv := &Server{Access: access} | ||
ts := httptest.NewServer(srv.handler()) | ||
defer ts.Close() | ||
|
||
noRedirectClient := &http.Client{ | ||
CheckRedirect: func(req *http.Request, via []*http.Request) error { | ||
return http.ErrUseLastResponse | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(access+tt.uri, func(t *testing.T) { | ||
resp, err := noRedirectClient.Get(ts.URL + tt.uri) | ||
if err != nil { | ||
t.Fatalf("got %v want nil", err) | ||
} | ||
if got, want := resp.StatusCode, tt.code; got != want { | ||
t.Fatalf("got code %d want %d", got, want) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
roTests := []test{ | ||
{"/api/manual", 403}, | ||
{"/api/config", 200}, | ||
{"/api/routes", 200}, | ||
{"/api/version", 200}, | ||
{"/manual", 403}, | ||
{"/routes", 200}, | ||
{"/health", 200}, | ||
{"/logo.svg", 200}, | ||
{"/", 303}, | ||
} | ||
|
||
rwTests := []test{ | ||
{"/api/manual", 200}, | ||
{"/api/config", 200}, | ||
{"/api/routes", 200}, | ||
{"/api/version", 200}, | ||
{"/manual", 200}, | ||
{"/routes", 200}, | ||
{"/health", 200}, | ||
{"/logo.svg", 200}, | ||
{"/", 303}, | ||
} | ||
|
||
testAccess("ro", roTests) | ||
testAccess("rw", rwTests) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,7 @@ type UI struct { | |
Listen Listen | ||
Color string | ||
Title string | ||
Access string | ||
} | ||
|
||
type Proxy struct { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters