New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conditionally deny access to web console #4046
Changes from 2 commits
c8ca2fd
465193b
bbce458
82692ae
00894c5
86a2523
70af553
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// +build integration,!no-etcd | ||
|
||
package integration | ||
|
||
import ( | ||
"crypto/tls" | ||
"net/http" | ||
"testing" | ||
|
||
configapi "github.com/openshift/origin/pkg/cmd/server/api" | ||
testutil "github.com/openshift/origin/test/util" | ||
) | ||
|
||
var ( | ||
stableWebConsoleEndpoints = []string{"healthz", "login"} | ||
switchableWebConsoleEndpoints = []string{"console", "console/", "console/java"} | ||
) | ||
|
||
func tryAccessURL(t *testing.T, url string, expectedStatus int) { | ||
transport := &http.Transport{ | ||
TLSClientConfig: &tls.Config{ | ||
InsecureSkipVerify: true, | ||
}, | ||
} | ||
|
||
req, err := http.NewRequest("GET", url, nil) | ||
req.Header.Set("Accept", "text/html") | ||
resp, err := transport.RoundTrip(req) | ||
if err != nil { | ||
t.Errorf("Unexpected error while accessing %s: %v", url, err) | ||
} | ||
if resp.StatusCode != expectedStatus { | ||
t.Errorf("Expected status %d for %s, got %d", expectedStatus, url, resp.StatusCode) | ||
} | ||
} | ||
|
||
func TestAccessOriginWebConsole(t *testing.T) { | ||
masterOptions, err := testutil.DefaultMasterOptions() | ||
if err != nil { | ||
t.Fatalf("unexpected error: %v", err) | ||
} | ||
if _, err = testutil.StartConfiguredMaster(masterOptions); err != nil { | ||
t.Fatalf("unexpected error: %v", err) | ||
} | ||
|
||
allEndpoints := append(stableWebConsoleEndpoints, switchableWebConsoleEndpoints...) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this (potentially) mutates the global variable There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would just inline the paths and statuses you expect in the tests
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. access There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good points. |
||
for _, endpoint := range allEndpoints { | ||
url := masterOptions.AssetConfig.MasterPublicURL + "/" + endpoint | ||
expectedStatus := http.StatusOK | ||
if endpoint == "console" { | ||
expectedStatus = http.StatusMovedPermanently | ||
} | ||
tryAccessURL(t, url, expectedStatus) | ||
} | ||
} | ||
|
||
func TestAccessDisabledWebConsole(t *testing.T) { | ||
masterOptions, err := testutil.DefaultMasterOptions() | ||
if err != nil { | ||
t.Fatalf("unexpected error: %v", err) | ||
} | ||
masterOptions.DisabledFeatures.Add(configapi.FeatureWebConsole) | ||
if _, err := testutil.StartConfiguredMaster(masterOptions); err != nil { | ||
t.Fatalf("unexpected error: %v", err) | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. access |
||
for _, endpoint := range stableWebConsoleEndpoints { | ||
url := masterOptions.AssetConfig.MasterPublicURL + "/" + endpoint | ||
tryAccessURL(t, url, http.StatusOK) | ||
} | ||
|
||
for _, endpoint := range switchableWebConsoleEndpoints { | ||
url := masterOptions.AssetConfig.MasterPublicURL + "/" + endpoint | ||
tryAccessURL(t, url, http.StatusForbidden) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
godoc, since the two conditions aren't obvious from the name of the function