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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c8ca2fd
Deny access to Web Console
465193b
Added integration test for disabling web console
bbce458
Test improvements
82692ae
Godoced exported method
00894c5
Inline test cases
86a2523
More polishment for integration test
70af553
Extended tested endpoints
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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,104 @@ | ||
// +build integration,!no-etcd | ||
|
||
package integration | ||
|
||
import ( | ||
"crypto/tls" | ||
"encoding/json" | ||
"io/ioutil" | ||
"net/http" | ||
"strings" | ||
"testing" | ||
|
||
configapi "github.com/openshift/origin/pkg/cmd/server/api" | ||
testutil "github.com/openshift/origin/test/util" | ||
) | ||
|
||
func tryAccessURL(t *testing.T, url string, expectedStatus int, expectedRedirectLocation string) *http.Response { | ||
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 %q: %v", url, err) | ||
return nil | ||
} | ||
if resp.StatusCode != expectedStatus { | ||
t.Errorf("Expected status %d for %q, got %d", expectedStatus, url, resp.StatusCode) | ||
} | ||
// ignore query parameters | ||
location := resp.Header.Get("Location") | ||
location = strings.SplitN(location, "?", 2)[0] | ||
if location != expectedRedirectLocation { | ||
t.Errorf("Expected redirecttion to %q for %q, got %q instead", expectedRedirectLocation, url, location) | ||
} | ||
return resp | ||
} | ||
|
||
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) | ||
} | ||
|
||
for endpoint, exp := range map[string]struct { | ||
statusCode int | ||
location string | ||
}{ | ||
"": {http.StatusFound, masterOptions.AssetConfig.PublicURL}, | ||
"healthz": {http.StatusOK, ""}, | ||
"login": {http.StatusOK, ""}, | ||
"oauth/token/request": {http.StatusFound, masterOptions.AssetConfig.MasterPublicURL + "/oauth/authorize"}, | ||
"console": {http.StatusMovedPermanently, "/console/"}, | ||
"console/": {http.StatusOK, ""}, | ||
"console/java": {http.StatusOK, ""}, | ||
} { | ||
url := masterOptions.AssetConfig.MasterPublicURL + "/" + endpoint | ||
tryAccessURL(t, url, exp.statusCode, exp.location) | ||
} | ||
} | ||
|
||
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 |
||
resp := tryAccessURL(t, masterOptions.AssetConfig.MasterPublicURL+"/", http.StatusOK, "") | ||
body, err := ioutil.ReadAll(resp.Body) | ||
if err != nil { | ||
t.Errorf("failed to read reposponse's body: %v", err) | ||
} else { | ||
var value interface{} | ||
if err = json.Unmarshal(body, &value); err != nil { | ||
t.Errorf("expected json body which couldn't be parsed: %v, got: %s", err, body) | ||
} | ||
} | ||
|
||
for endpoint, exp := range map[string]struct { | ||
statusCode int | ||
location string | ||
}{ | ||
"healthz": {http.StatusOK, ""}, | ||
"login": {http.StatusOK, ""}, | ||
"oauth/token/request": {http.StatusFound, masterOptions.AssetConfig.MasterPublicURL + "/oauth/authorize"}, | ||
"console": {http.StatusForbidden, ""}, | ||
"console/": {http.StatusForbidden, ""}, | ||
"console/java": {http.StatusForbidden, ""}, | ||
} { | ||
url := masterOptions.AssetConfig.MasterPublicURL + "/" + endpoint | ||
tryAccessURL(t, url, exp.statusCode, exp.location) | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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