Skip to content

Commit 5a8ebc8

Browse files
authored
Merge pull request #3733 from ActiveState/mitchell/cp-1084
Attempt to fix more tests.
2 parents 0134486 + 4b74e59 commit 5a8ebc8

File tree

5 files changed

+49
-69
lines changed

5 files changed

+49
-69
lines changed

.github/workflows/build.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ jobs:
205205
id: unit_tests
206206
shell: bash
207207
run: parallelize results Unit-Tests | gotestfmt -hide empty-packages
208-
continue-on-error: ${{ github.event_name != 'schedule' }}
208+
continue-on-error: true # This is captured by the "Check if Unit Tests Failed" step
209209

210210
- # === "Build: CLI" ===
211211
name: "Build: CLI"
@@ -375,9 +375,9 @@ jobs:
375375
INTEGRATION_TEST_TOKEN: ${{ secrets.INTEGRATION_TEST_TOKEN }}
376376
PLATFORM_API_TOKEN: ${{ secrets.PLATFORM_API_TOKEN }}
377377

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

internal/keypairs/rsa_keypair_test.go

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ func (suite *RSAKeypairTestSuite) TestGenerateRSA_UsesMinimumBitLength() {
3131
func (suite *RSAKeypairTestSuite) TestGenerateRSA_GeneratesRSAKeypair() {
3232
kp, err := keypairs.GenerateRSA(keypairs.MinimumRSABitLength)
3333
suite.Require().Nil(err)
34-
suite.Regexp(`^-{5}BEGIN RSA PRIVATE KEY-{5}\s[[:alnum:]/+=]{44}\s-{5}END RSA PRIVATE KEY-{5}\s`, kp.EncodePrivateKey())
34+
suite.Regexp(`^-{5}BEGIN RSA PRIVATE KEY-{5}\s[[:alnum:]/+=\s]+?\s-{5}END RSA PRIVATE KEY-{5}`, kp.EncodePrivateKey())
3535

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

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

54-
func (suite *RSAKeypairTestSuite) TestRSAKeypair_MessageTooLongForKeySize() {
55-
kp, err := keypairs.GenerateRSA(keypairs.MinimumRSABitLength)
56-
suite.Require().Nil(err)
57-
58-
encMsg, err := kp.Encrypt([]byte("howdy doody"))
59-
suite.Nil(encMsg)
60-
suite.Require().Error(err)
61-
suite.Contains(err.Error(), "EncryptOAEP failed")
62-
}
63-
6454
func (suite *RSAKeypairTestSuite) TestRSAKeypair_EncryptsAndDecrypts() {
65-
kp, err := keypairs.GenerateRSA(1024)
55+
kp, err := keypairs.GenerateRSA(keypairs.MinimumRSABitLength)
6656
suite.Require().Nil(err)
6757

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

7767
func (suite *RSAKeypairTestSuite) TestRSAKeypair_EncodesAndDeccodesEncryptedValues() {
78-
kp, err := keypairs.GenerateRSA(1024)
68+
kp, err := keypairs.GenerateRSA(keypairs.MinimumRSABitLength)
7969
suite.Require().Nil(err)
8070

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

190180
func Test_RSAKeypair_TestSuite(t *testing.T) {
191-
t.Skip("This is still captured by integration tests, but for now we're skipping the unit test as it" +
192-
" prevents CI from running and we need time to devise a proper solution.")
193181
suite.Run(t, new(RSAKeypairTestSuite))
194182
}

internal/secrets/share_test.go

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -52,27 +52,6 @@ func (suite *SecretsSharingTestSuite) TestFailure_FirstShareHasBadlyEncryptedVal
5252
suite.Require().Error(err)
5353
}
5454

55-
func (suite *SecretsSharingTestSuite) TestFailure_FailedToEncryptForTargetUser() {
56-
suite.T().Skip("This is still captured by integration tests, but for now we're skipping the unit test as it" +
57-
" prevents CI from running and we need time to devise a proper solution.")
58-
shortKeypair, err := keypairs.GenerateRSA(keypairs.MinimumRSABitLength)
59-
suite.Require().NoError(err)
60-
61-
// this is a valid public key, but will be too short for encrypting with
62-
shortPubKey, err := shortKeypair.EncodePublicKey()
63-
suite.Require().NoError(err)
64-
65-
encrValue, err := suite.sourceKeypair.EncryptAndEncode([]byte("luv 2 encrypt data"))
66-
suite.Require().NoError(err)
67-
68-
newShares, err := secrets.ShareFromDiff(suite.sourceKeypair, &secrets_models.UserSecretDiff{
69-
PublicKey: &shortPubKey,
70-
Shares: []*secrets_models.UserSecretShare{newUserSecretShare("", "FOO", encrValue)},
71-
})
72-
suite.Nil(newShares)
73-
suite.Require().Error(err)
74-
}
75-
7655
func (suite *SecretsSharingTestSuite) TestSuccess_ReceivedEmptySharesList() {
7756
newShares, err := secrets.ShareFromDiff(suite.sourceKeypair, &secrets_models.UserSecretDiff{
7857
PublicKey: &suite.targetPubKey,

internal/testhelpers/e2e/session.go

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -768,13 +768,27 @@ func (s *Session) SetupRCFile() {
768768
if runtime.GOOS == "windows" {
769769
return
770770
}
771-
s.T.Setenv("HOME", s.Dirs.HomeDir)
772-
defer s.T.Setenv("HOME", os.Getenv("HOME"))
773-
774-
cfg, err := config.New()
775-
require.NoError(s.T, err)
771+
s.WithEnv(func() {
772+
s.SetupRCFileCustom(subshell.New(s.cfg))
773+
})
774+
}
776775

777-
s.SetupRCFileCustom(subshell.New(cfg))
776+
func (s *Session) WithEnv(do func()) {
777+
env := osutils.EnvSliceToMap(s.Env)
778+
for k, v := range env {
779+
_, exists := os.LookupEnv(k)
780+
if exists {
781+
defer s.T.Setenv(k, os.Getenv(k))
782+
} else {
783+
defer func() {
784+
if err := os.Unsetenv(k); err != nil {
785+
s.T.Logf("Failed to unset env var %s: %v", k, err)
786+
}
787+
}()
788+
}
789+
s.T.Setenv(k, v)
790+
}
791+
do()
778792
}
779793

780794
func (s *Session) SetupRCFileCustom(subshell subshell.SubShell) {
@@ -790,7 +804,11 @@ func (s *Session) SetupRCFileCustom(subshell subshell.SubShell) {
790804
} else {
791805
err = fileutils.Touch(filepath.Join(s.Dirs.HomeDir, filepath.Base(rcFile)))
792806
}
793-
require.NoError(s.T, err)
807+
require.NoError(s.T, err, errs.JoinMessage(err))
808+
}
809+
810+
func (s *Session) Config() *config.Instance {
811+
return s.cfg
794812
}
795813

796814
func (s *Session) SetConfig(key string, value interface{}) {

test/integration/shell_int_test.go

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -193,20 +193,25 @@ func (suite *ShellIntegrationTestSuite) TestUseShellUpdates() {
193193
ts := e2e.New(suite.T(), false)
194194
defer ts.Close()
195195

196-
suite.SetupRCFile(ts)
196+
if runtime.GOOS != "windows" {
197+
ts.SetupRCFileCustom(&bash.SubShell{})
198+
ts.SetupRCFileCustom(&zsh.SubShell{})
199+
}
197200

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

202205
// Create a zsh RC file
203206
var zshRcFile string
204-
var err error
205-
if runtime.GOOS != "windows" {
206-
zsh := &zsh.SubShell{}
207-
zshRcFile, err = zsh.RcFile()
208-
suite.NoError(err)
209-
}
207+
ts.WithEnv(func() {
208+
var err error
209+
if runtime.GOOS != "windows" {
210+
zsh := &zsh.SubShell{}
211+
zshRcFile, err = zsh.RcFile()
212+
suite.NoError(err)
213+
}
214+
})
210215

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

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

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

240-
func (suite *ShellIntegrationTestSuite) SetupRCFile(ts *e2e.Session) {
241-
if runtime.GOOS == "windows" {
242-
return
243-
}
244-
245-
ts.SetupRCFile()
246-
ts.SetupRCFileCustom(&zsh.SubShell{})
247-
}
248-
249244
func (suite *ShellIntegrationTestSuite) TestRuby() {
250245
suite.OnlyRunForTags(tagsuite.Shell)
251246
ts := e2e.New(suite.T(), false)

0 commit comments

Comments
 (0)