Skip to content
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
8 changes: 4 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ jobs:
id: unit_tests
shell: bash
run: parallelize results Unit-Tests | gotestfmt -hide empty-packages
continue-on-error: ${{ github.event_name != 'schedule' }}
continue-on-error: true # This is captured by the "Check if Unit Tests Failed" step

- # === "Build: CLI" ===
name: "Build: CLI"
Expand Down Expand Up @@ -375,9 +375,9 @@ jobs:
INTEGRATION_TEST_TOKEN: ${{ secrets.INTEGRATION_TEST_TOKEN }}
PLATFORM_API_TOKEN: ${{ secrets.PLATFORM_API_TOKEN }}

- # === Fail If Unscheduled Unit Tests Failed (Expand 'Unit Tests' above for more information) ===
name: Fail If Unscheduled Unit Tests Failed
if: github.event_name != 'schedule' && steps.unit_tests.outcome == 'failure'
- # === Check if Unit Tests Failed ===
name: Check if Unit Tests Failed
if: steps.unit_tests.outcome == 'failure'
shell: bash
run: exit 1

Expand Down
20 changes: 4 additions & 16 deletions internal/keypairs/rsa_keypair_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ func (suite *RSAKeypairTestSuite) TestGenerateRSA_UsesMinimumBitLength() {
func (suite *RSAKeypairTestSuite) TestGenerateRSA_GeneratesRSAKeypair() {
kp, err := keypairs.GenerateRSA(keypairs.MinimumRSABitLength)
suite.Require().Nil(err)
suite.Regexp(`^-{5}BEGIN RSA PRIVATE KEY-{5}\s[[:alnum:]/+=]{44}\s-{5}END RSA PRIVATE KEY-{5}\s`, kp.EncodePrivateKey())
suite.Regexp(`^-{5}BEGIN RSA PRIVATE KEY-{5}\s[[:alnum:]/+=\s]+?\s-{5}END RSA PRIVATE KEY-{5}`, kp.EncodePrivateKey())

encPubKey, err := kp.EncodePublicKey()
suite.Require().Nil(err)
suite.Regexp(`^-{5}BEGIN RSA PUBLIC KEY-{5}\s[[:alnum:]/+=]{44}\s-{5}END RSA PUBLIC KEY-{5}\s`, encPubKey)
suite.Regexp(`^-{5}BEGIN RSA PUBLIC KEY-{5}\s[[:alnum:]/+=\s]+\s-{5}END RSA PUBLIC KEY-{5}`, encPubKey)
}

func (suite *RSAKeypairTestSuite) TestRSAKeypair_EncryptAndEncodePrivateKey() {
Expand All @@ -51,18 +51,8 @@ func (suite *RSAKeypairTestSuite) TestRSAKeypair_EncryptAndEncodePrivateKey() {
suite.Regexp(`-{5}END RSA PRIVATE KEY-{5}\s`, keyPEM)
}

func (suite *RSAKeypairTestSuite) TestRSAKeypair_MessageTooLongForKeySize() {
kp, err := keypairs.GenerateRSA(keypairs.MinimumRSABitLength)
suite.Require().Nil(err)

encMsg, err := kp.Encrypt([]byte("howdy doody"))
suite.Nil(encMsg)
suite.Require().Error(err)
suite.Contains(err.Error(), "EncryptOAEP failed")
}

func (suite *RSAKeypairTestSuite) TestRSAKeypair_EncryptsAndDecrypts() {
kp, err := keypairs.GenerateRSA(1024)
kp, err := keypairs.GenerateRSA(keypairs.MinimumRSABitLength)
suite.Require().Nil(err)

encryptedMsg, err := kp.Encrypt([]byte("howdy doody"))
Expand All @@ -75,7 +65,7 @@ func (suite *RSAKeypairTestSuite) TestRSAKeypair_EncryptsAndDecrypts() {
}

func (suite *RSAKeypairTestSuite) TestRSAKeypair_EncodesAndDeccodesEncryptedValues() {
kp, err := keypairs.GenerateRSA(1024)
kp, err := keypairs.GenerateRSA(keypairs.MinimumRSABitLength)
suite.Require().Nil(err)

encryptedMsg, err := kp.EncryptAndEncode([]byte("howdy doody"))
Expand Down Expand Up @@ -188,7 +178,5 @@ func (suite *RSAKeypairTestSuite) TestParseEncryptedRSA_IncorrectPassphrase() {
}

func Test_RSAKeypair_TestSuite(t *testing.T) {
t.Skip("This is still captured by integration tests, but for now we're skipping the unit test as it" +
" prevents CI from running and we need time to devise a proper solution.")
suite.Run(t, new(RSAKeypairTestSuite))
}
21 changes: 0 additions & 21 deletions internal/secrets/share_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,27 +52,6 @@ func (suite *SecretsSharingTestSuite) TestFailure_FirstShareHasBadlyEncryptedVal
suite.Require().Error(err)
}

func (suite *SecretsSharingTestSuite) TestFailure_FailedToEncryptForTargetUser() {
suite.T().Skip("This is still captured by integration tests, but for now we're skipping the unit test as it" +
" prevents CI from running and we need time to devise a proper solution.")
shortKeypair, err := keypairs.GenerateRSA(keypairs.MinimumRSABitLength)
suite.Require().NoError(err)

// this is a valid public key, but will be too short for encrypting with
shortPubKey, err := shortKeypair.EncodePublicKey()
suite.Require().NoError(err)

encrValue, err := suite.sourceKeypair.EncryptAndEncode([]byte("luv 2 encrypt data"))
suite.Require().NoError(err)

newShares, err := secrets.ShareFromDiff(suite.sourceKeypair, &secrets_models.UserSecretDiff{
PublicKey: &shortPubKey,
Shares: []*secrets_models.UserSecretShare{newUserSecretShare("", "FOO", encrValue)},
})
suite.Nil(newShares)
suite.Require().Error(err)
}

func (suite *SecretsSharingTestSuite) TestSuccess_ReceivedEmptySharesList() {
newShares, err := secrets.ShareFromDiff(suite.sourceKeypair, &secrets_models.UserSecretDiff{
PublicKey: &suite.targetPubKey,
Expand Down
32 changes: 25 additions & 7 deletions internal/testhelpers/e2e/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -768,13 +768,27 @@ func (s *Session) SetupRCFile() {
if runtime.GOOS == "windows" {
return
}
s.T.Setenv("HOME", s.Dirs.HomeDir)
defer s.T.Setenv("HOME", os.Getenv("HOME"))

cfg, err := config.New()
require.NoError(s.T, err)
s.WithEnv(func() {
s.SetupRCFileCustom(subshell.New(s.cfg))
})
}

s.SetupRCFileCustom(subshell.New(cfg))
func (s *Session) WithEnv(do func()) {
env := osutils.EnvSliceToMap(s.Env)
for k, v := range env {
_, exists := os.LookupEnv(k)
if exists {
defer s.T.Setenv(k, os.Getenv(k))
} else {
defer func() {
if err := os.Unsetenv(k); err != nil {
s.T.Logf("Failed to unset env var %s: %v", k, err)
}
}()
}
s.T.Setenv(k, v)
}
do()
}

func (s *Session) SetupRCFileCustom(subshell subshell.SubShell) {
Expand All @@ -790,7 +804,11 @@ func (s *Session) SetupRCFileCustom(subshell subshell.SubShell) {
} else {
err = fileutils.Touch(filepath.Join(s.Dirs.HomeDir, filepath.Base(rcFile)))
}
require.NoError(s.T, err)
require.NoError(s.T, err, errs.JoinMessage(err))
}

func (s *Session) Config() *config.Instance {
return s.cfg
}

func (s *Session) SetConfig(key string, value interface{}) {
Expand Down
37 changes: 16 additions & 21 deletions test/integration/shell_int_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,20 +193,25 @@ func (suite *ShellIntegrationTestSuite) TestUseShellUpdates() {
ts := e2e.New(suite.T(), false)
defer ts.Close()

suite.SetupRCFile(ts)
if runtime.GOOS != "windows" {
ts.SetupRCFileCustom(&bash.SubShell{})
ts.SetupRCFileCustom(&zsh.SubShell{})
}

cp := ts.Spawn("checkout", "ActiveState-CLI/Empty")
cp.Expect("Checked out project")
cp.ExpectExitCode(0)

// Create a zsh RC file
var zshRcFile string
var err error
if runtime.GOOS != "windows" {
zsh := &zsh.SubShell{}
zshRcFile, err = zsh.RcFile()
suite.NoError(err)
}
ts.WithEnv(func() {
var err error
if runtime.GOOS != "windows" {
zsh := &zsh.SubShell{}
zshRcFile, err = zsh.RcFile()
suite.NoError(err)
}
})

cp = ts.SpawnWithOpts(
e2e.OptArgs("use", "ActiveState-CLI/Empty"),
Expand All @@ -216,13 +221,12 @@ func (suite *ShellIntegrationTestSuite) TestUseShellUpdates() {
cp.ExpectExitCode(0)

// Ensure both bash and zsh RC files are updated
cfg, err := config.New()
suite.NoError(err)
rcfile, err := subshell.New(cfg).RcFile()
rcfile, err := subshell.New(ts.Config()).RcFile()
rcfile = filepath.Join(ts.Dirs.HomeDir, filepath.Base(rcfile))
if runtime.GOOS != "windows" && fileutils.FileExists(rcfile) {
suite.NoError(err)
suite.Contains(string(fileutils.ReadFileUnsafe(rcfile)), ts.Dirs.DefaultBin, "PATH does not have your project in it")
suite.Contains(string(fileutils.ReadFileUnsafe(zshRcFile)), ts.Dirs.DefaultBin, "PATH does not have your project in it")
suite.Contains(string(fileutils.ReadFileUnsafe(rcfile)), ts.Dirs.DefaultBin, rcfile+": PATH does not have your project in it")
suite.Contains(string(fileutils.ReadFileUnsafe(zshRcFile)), ts.Dirs.DefaultBin, zshRcFile+": PATH does not have your project in it")
}
}

Expand All @@ -237,15 +241,6 @@ func (suite *ShellIntegrationTestSuite) TestJSON() {
AssertValidJSON(suite.T(), cp)
}

func (suite *ShellIntegrationTestSuite) SetupRCFile(ts *e2e.Session) {
if runtime.GOOS == "windows" {
return
}

ts.SetupRCFile()
ts.SetupRCFileCustom(&zsh.SubShell{})
}

func (suite *ShellIntegrationTestSuite) TestRuby() {
suite.OnlyRunForTags(tagsuite.Shell)
ts := e2e.New(suite.T(), false)
Expand Down
Loading