Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added integration test for disabling web console
and removed redundant tests from test-cmd.sh Signed-off-by: Michal Minar <miminar@redhat.com>
- Loading branch information
Michal Minar
committed
Aug 11, 2015
1 parent
c8ca2fd
commit 465193b
Showing
3 changed files
with
88 additions
and
95 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,6 @@ | ||
package origin | ||
|
||
import ( | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
|
||
"github.com/emicklei/go-restful" | ||
|
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,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...) | ||
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) | ||
} | ||
|
||
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) | ||
} | ||
} |