|
| 1 | +Describe 'Ensuring that corrupted .arguments file responds correctly for <CommandDescription> <Command>' -ForEach @( |
| 2 | + @{ |
| 3 | + Command = 'install' |
| 4 | + CommandDescription = 'default' |
| 5 | + ExpectedExitCode = 0 |
| 6 | + Parameters = @('installpackage') |
| 7 | + } |
| 8 | + # It seems that upgrade and uninstall exit with -1 when the beforemodify fails. |
| 9 | + # As such, these tests will expect those exit codes for success. |
| 10 | + @{ |
| 11 | + Command = 'upgrade' |
| 12 | + CommandDescription = 'default' |
| 13 | + ExpectedExitCode = -1 |
| 14 | + Parameters = @('upgradepackage') |
| 15 | + } |
| 16 | + @{ |
| 17 | + Command = 'upgrade' |
| 18 | + CommandDescription = 'remember' |
| 19 | + ExpectedExitCode = 1 |
| 20 | + Parameters = @('upgradepackage') |
| 21 | + } |
| 22 | + @{ |
| 23 | + Command = 'download' |
| 24 | + CommandDescription = 'default' |
| 25 | + ExpectedExitCode = 0 |
| 26 | + Parameters = @('upgradepackage') |
| 27 | + } |
| 28 | + @{ |
| 29 | + Command = 'list' |
| 30 | + CommandDescription = 'verbose' |
| 31 | + ExpectedExitCode = 0 |
| 32 | + Parameters = @('--verbose') |
| 33 | + } |
| 34 | + @{ |
| 35 | + Command = 'list' |
| 36 | + CommandDescription = 'default' |
| 37 | + ExpectedExitCode = 0 |
| 38 | + Parameters = @() |
| 39 | + } |
| 40 | + @{ |
| 41 | + Command = 'info' |
| 42 | + CommandDescription = 'verbose' |
| 43 | + ExpectedExitCode = 0 |
| 44 | + Parameters = @('upgradepackage', '--local-only') |
| 45 | + } |
| 46 | + # It seems that upgrade and uninstall exit with -1 when the beforemodify fails. |
| 47 | + # As such, these tests will expect those exit codes for success. |
| 48 | + @{ |
| 49 | + Command = 'uninstall' |
| 50 | + CommandDescription = 'default' |
| 51 | + ExpectedExitCode = -1 |
| 52 | + Parameters = @('upgradepackage') |
| 53 | + } |
| 54 | + @{ |
| 55 | + Command = 'pin' |
| 56 | + CommandDescription = 'default' |
| 57 | + ExpectedExitCode = 0 |
| 58 | + Parameters = @('list') |
| 59 | + } |
| 60 | + @{ |
| 61 | + Command = 'pin' |
| 62 | + CommandDescription = 'default' |
| 63 | + ExpectedExitCode = 0 |
| 64 | + Parameters = @('add','-n=upgradepackage') |
| 65 | + } |
| 66 | +) -Tag ArgumentsFileDecryption { |
| 67 | + BeforeDiscovery { |
| 68 | + $HasLicensedExtension = Test-PackageIsEqualOrHigher -PackageName 'chocolatey.extension' -Version '6.0.0' |
| 69 | + } |
| 70 | + |
| 71 | + BeforeAll { |
| 72 | + Initialize-ChocolateyTestInstall |
| 73 | + } |
| 74 | + |
| 75 | + # Skip the download command if chocolatey.extension is not installed. |
| 76 | + Context 'Command (<Command>) failure scenario (<ErrorType>)' -Skip:($Command -eq 'download' -and -not $HasLicensedExtension) -ForEach @( |
| 77 | + @{ |
| 78 | + ErrorType = 'Base64 invalid' |
| 79 | + DecryptionError = 'The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters.' |
| 80 | + FileContents = 'InvalidBase64!' |
| 81 | + } |
| 82 | + @{ |
| 83 | + ErrorType = 'Invalid decryption' |
| 84 | + DecryptionError = 'Key not valid for use in specified state.' |
| 85 | + # The contents of this was taken from a throw away VM. |
| 86 | + FileContents = 'AQAAANCMnd8BFdERjHoAwE/Cl+sBAAAAn1/taDnOFUqGb17fBymxHQQAAAACAAAAAAAQZgAAAAEAACAAAAAU8gmqznJYKdkuj8bgk8sgg6Le3sbGoGkZOV3YtRFfwwAAAAAOgAAAAAIAACAAAAD1I9LYxrEhx9m71eF3VqyAike+XJTePhDAcrOilAFjQlAAAAA8lfiMR5Ns/AntLdVR3eBQSduCnipRCbdu/er/+YABMTzJDMGqnXuIsKwWoNIhrB14Yit4jVPipt3a/Nx18xx+YsnUewI4P6GlDL5do1y8mkAAAABMxvyPgCtN36BwAOXvJghIh9Hs8jUZOJtQIlWci8BnJkBmaaoSZ6pTGULk4TbFXMf/FK1NPo2mPM0YVL8QgJyK' |
| 87 | + } |
| 88 | + ) { |
| 89 | + BeforeAll { |
| 90 | + Restore-ChocolateyInstallSnapshot |
| 91 | + |
| 92 | + if ($CommandDescription -eq 'remember') { |
| 93 | + Enable-ChocolateyFeature -Name useRememberedArgumentsForUpgrades |
| 94 | + } |
| 95 | + |
| 96 | + Invoke-Choco install upgradepackage --version 1.0.0 |
| 97 | + $argumentsFile = Join-Path $env:ChocolateyInstall ".chocolatey/upgradepackage.1.0.0/.arguments" |
| 98 | + $FileContents | Set-Content -Path $argumentsFile -Encoding utf8 -Force |
| 99 | + |
| 100 | + $Output = Invoke-Choco $Command @Parameters --debug |
| 101 | + } |
| 102 | + |
| 103 | + AfterAll { |
| 104 | + Remove-ChocolateyInstallSnapshot |
| 105 | + } |
| 106 | + |
| 107 | + It 'Exits correctly (<ExpectedExitCode>)' { |
| 108 | + $Output.ExitCode | Should -Be $ExpectedExitCode -Because $Output.String |
| 109 | + } |
| 110 | + |
| 111 | + It 'Outputs expected messages' { |
| 112 | + $shouldContain = -not ($CommandDescription -eq 'verbose' -or $CommandDescription -eq 'remember') |
| 113 | + $Output.Lines | Should -Not:$shouldContain -Contain "We failed to decrypt $($env:ChocolateyInstall)\.chocolatey\upgradepackage.1.0.0\.arguments. Error from decryption: $DecryptionError" -Because $Output.String |
| 114 | + } |
| 115 | + } |
| 116 | +} |
0 commit comments