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

Add bare minimum encrypt-file spec and fix the command #715

Merged
merged 2 commits into from
Mar 4, 2020
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
2 changes: 1 addition & 1 deletion lib/travis/cli/encrypt_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def store_command(command)
end

def decrypt_command(path)
"openssl aes-256-cbc -K $#{env_name(:key)} -iv $#{env_name(:iv)} -in #{escape_path(path)} -out #{escape_path(decrypt_to)} -d"
"openssl aes-256-cbc -K $#{env_name(path, :key)} -iv $#{env_name(path, :iv)} -in #{escape_path(path)} -out #{escape_path(decrypt_to)} -d"
end

def set_env_vars(input_path)
Expand Down
20 changes: 20 additions & 0 deletions spec/cli/encrypt_file_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require 'spec_helper'
require 'fileutils'
require 'digest'

describe Travis::CLI::EncryptFile do
CMD_TARGET = 'README.md'

before :each do
Digest.stub(:hexencode).and_return "randomhex" # to avoid relying on Dir.pwd value for hex
end

after :each do
FileUtils.rm_f "#{CMD_TARGET}.enc"
end

example "travis encrypt-file #{CMD_TARGET}" do
run_cli('encrypt-file', CMD_TARGET).should be_success
File.exists?("#{CMD_TARGET}.enc").should be true
end
end
50 changes: 50 additions & 0 deletions spec/support/fake_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,56 @@ def authorized?
}]}.to_json
end

#### for encrypt_file spec
get '/settings/env_vars/' do
# p params
$params = params
{
"env_vars":[
{
"id": "8aa1c74d-dcc4-4e41-9087-1326b7c68abd",
"name": "encrypted_randomhex_key",
"value": "super_secret_key",
"public": false,
"repository_id": 891
},
{
"id": "b2ed30b9-622d-4bd7-928b-ba5aad7ba6a1",
"name": "encrypted_randomhex_iv",
"value": "super_secret_iv",
"public": false,
"repository_id": 891
}
]
}.to_json
end

patch '/settings/env_vars/8aa1c74d-dcc4-4e41-9087-1326b7c68abd' do
$params = params
{
"env_var": {
"id": "8aa1c74d-dcc4-4e41-9087-1326b7c68abd",
"name": "encrypted_randomhex_key",
"value": "new_super_secret_key",
"public": false,
"repository_id": 891
}
}.to_json
end

patch '/settings/env_vars/b2ed30b9-622d-4bd7-928b-ba5aad7ba6a1' do
$params = params
{
"env_var": {
"id": "b2ed30b9-622d-4bd7-928b-ba5aad7ba6a1",
"name": "encrypted_randomhex_iv",
"value": "new_super_secret_iv",
"public": false,
"repository_id": 891
}
}.to_json
end

post '/requests' do
$params = params
"{}"
Expand Down