-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1893 from tirthct/ocm-6926-fix-mandatory-env
OCM-6926 | fix: Added back the condition to check for empty env flag
- Loading branch information
1 parent
242856b
commit a583c12
Showing
3 changed files
with
144 additions
and
18 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 |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package login | ||
|
||
import ( | ||
"os" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
|
||
"github.com/openshift/rosa/pkg/config" | ||
"github.com/openshift/rosa/pkg/fedramp" | ||
"github.com/openshift/rosa/pkg/rosa" | ||
) | ||
|
||
var _ = Describe("Validate login command", func() { | ||
|
||
AfterEach(func() { | ||
fedramp.Disable() | ||
os.Setenv("AWS_REGION", "") | ||
}) | ||
|
||
Context("login command", func() { | ||
When("logging into FedRAMP", func() { | ||
env = "staging" | ||
It("only 'region' is FedRAMP", func() { | ||
os.Setenv("AWS_REGION", "us-gov-west-1") | ||
// Load the configuration file: | ||
cfg, err := config.Load() | ||
Expect(err).ToNot(HaveOccurred()) | ||
if cfg == nil { | ||
cfg = new(config.Config) | ||
} | ||
err = CheckAndLogIntoFedramp(false, false, cfg, "", rosa.NewRuntime()) | ||
Expect(err).ToNot(HaveOccurred()) | ||
}) | ||
It("only 'govcloud' flag is true", func() { | ||
os.Setenv("AWS_REGION", "us-east-1") | ||
// Load the configuration file: | ||
cfg, err := config.Load() | ||
Expect(err).ToNot(HaveOccurred()) | ||
if cfg == nil { | ||
cfg = new(config.Config) | ||
} | ||
err = CheckAndLogIntoFedramp(true, false, cfg, "", rosa.NewRuntime()) | ||
Expect(err).To(HaveOccurred()) | ||
}) | ||
It("only 'cfg' has FedRAMP", func() { | ||
os.Setenv("AWS_REGION", "us-east-1") | ||
// Load the configuration file: | ||
cfg, err := config.Load() | ||
Expect(err).ToNot(HaveOccurred()) | ||
if cfg == nil { | ||
cfg = new(config.Config) | ||
} | ||
cfg.FedRAMP = true | ||
err = CheckAndLogIntoFedramp(false, false, cfg, "", rosa.NewRuntime()) | ||
Expect(err).To(HaveOccurred()) | ||
}) | ||
It("'cfg' has FedRAMP and region is govcloud", func() { | ||
os.Setenv("AWS_REGION", "us-gov-east-1") | ||
// Load the configuration file: | ||
cfg, err := config.Load() | ||
Expect(err).ToNot(HaveOccurred()) | ||
if cfg == nil { | ||
cfg = new(config.Config) | ||
} | ||
cfg.FedRAMP = true | ||
err = CheckAndLogIntoFedramp(false, false, cfg, "", rosa.NewRuntime()) | ||
Expect(err).ToNot(HaveOccurred()) | ||
}) | ||
It("env is empty", func() { | ||
os.Setenv("AWS_REGION", "us-gov-east-1") | ||
// Load the configuration file: | ||
cfg, err := config.Load() | ||
Expect(err).ToNot(HaveOccurred()) | ||
if cfg == nil { | ||
cfg = new(config.Config) | ||
} | ||
env = "" | ||
cfg.FedRAMP = true | ||
err = CheckAndLogIntoFedramp(false, false, cfg, "", rosa.NewRuntime()) | ||
Expect(err).ToNot(HaveOccurred()) | ||
Expect(env).To(Equal("production")) | ||
}) | ||
}) | ||
}) | ||
}) |
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,13 @@ | ||
package login | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestLogin(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "Login Suite") | ||
} |