Skip to content
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

fix: tests refactoring #1950

Merged
merged 1 commit into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions pkg/api/authn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ func TestAPIKeys(t *testing.T) {
conf := config.New()
conf.HTTP.Port = port

htpasswdPath := test.MakeHtpasswdFile()
username, seedUser := test.GenerateRandomString()
password, seedPass := test.GenerateRandomString()
htpasswdPath := test.MakeHtpasswdFileFromString(test.GetCredString(username, password))
defer os.Remove(htpasswdPath)

mockOIDCServer, err := authutils.MockOIDCRun()
Expand Down Expand Up @@ -125,6 +127,7 @@ func TestAPIKeys(t *testing.T) {
conf.Extensions.UI.Enable = &defaultVal

ctlr := api.NewController(conf)
ctlr.Log.Info().Int64("seedUser", seedUser).Int64("seedPass", seedPass).Msg("random seed for username & password")
dir := t.TempDir()

ctlr.Config.Storage.RootDirectory = dir
Expand All @@ -145,7 +148,7 @@ func TestAPIKeys(t *testing.T) {
Convey("API key retrieved with basic auth", func() {
resp, err := resty.R().
SetBody(reqBody).
SetBasicAuth("test", "test").
SetBasicAuth(username, password).
Post(baseURL + constants.APIKeyPath)
So(err, ShouldBeNil)
So(resp, ShouldNotBeNil)
Expand All @@ -162,15 +165,15 @@ func TestAPIKeys(t *testing.T) {
So(email, ShouldNotBeEmpty)

resp, err = resty.R().
SetBasicAuth("test", apiKeyResponse.APIKey).
SetBasicAuth(username, apiKeyResponse.APIKey).
Get(baseURL + "/v2/_catalog")
So(err, ShouldBeNil)
So(resp, ShouldNotBeNil)
So(resp.StatusCode(), ShouldEqual, http.StatusOK)

// get API key list with basic auth
resp, err = resty.R().
SetBasicAuth("test", "test").
SetBasicAuth(username, password).
Get(baseURL + constants.APIKeyPath)
So(err, ShouldBeNil)
So(resp, ShouldNotBeNil)
Expand All @@ -189,7 +192,7 @@ func TestAPIKeys(t *testing.T) {
// add another one
resp, err = resty.R().
SetBody(reqBody).
SetBasicAuth("test", "test").
SetBasicAuth(username, password).
Post(baseURL + constants.APIKeyPath)
So(err, ShouldBeNil)
So(resp, ShouldNotBeNil)
Expand All @@ -199,15 +202,15 @@ func TestAPIKeys(t *testing.T) {
So(err, ShouldBeNil)

resp, err = resty.R().
SetBasicAuth("test", apiKeyResponse.APIKey).
SetBasicAuth(username, apiKeyResponse.APIKey).
Get(baseURL + "/v2/_catalog")
So(err, ShouldBeNil)
So(resp, ShouldNotBeNil)
So(resp.StatusCode(), ShouldEqual, http.StatusOK)

// get API key list with api key auth
resp, err = resty.R().
SetBasicAuth("test", apiKeyResponse.APIKey).
SetBasicAuth(username, apiKeyResponse.APIKey).
Get(baseURL + constants.APIKeyPath)
So(err, ShouldBeNil)
So(resp, ShouldNotBeNil)
Expand Down Expand Up @@ -600,7 +603,7 @@ func TestAPIKeys(t *testing.T) {
So(len(apiKeyListResponse.APIKeys), ShouldEqual, 0)

resp, err = client.R().
SetBasicAuth("test", "test").
SetBasicAuth(username, password).
SetQueryParam("id", apiKeyResponse.UUID).
Delete(baseURL + constants.APIKeyPath)
So(err, ShouldBeNil)
Expand Down Expand Up @@ -832,7 +835,9 @@ func TestAPIKeys(t *testing.T) {
func TestAPIKeysOpenDBError(t *testing.T) {
Convey("Test API keys - unable to create database", t, func() {
conf := config.New()
htpasswdPath := test.MakeHtpasswdFile()
username, seedUser := test.GenerateRandomString()
password, seedPass := test.GenerateRandomString()
htpasswdPath := test.MakeHtpasswdFileFromString(test.GetCredString(username, password))
defer os.Remove(htpasswdPath)

mockOIDCServer, err := authutils.MockOIDCRun()
Expand Down Expand Up @@ -871,6 +876,7 @@ func TestAPIKeysOpenDBError(t *testing.T) {
}

ctlr := api.NewController(conf)
ctlr.Log.Info().Int64("seedUser", seedUser).Int64("seedPass", seedPass).Msg("random seed for username & password")
dir := t.TempDir()

err = os.Chmod(dir, 0o000)
Expand Down
Loading
Loading