gitc-ruby_gpg 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +3 -0
- data/.gitignore +26 -0
- data/CHANGELOG.markdown +11 -0
- data/LICENSE +20 -0
- data/README.markdown +32 -0
- data/Rakefile +69 -0
- data/VERSION +1 -0
- data/cucumber.yml +1 -0
- data/features/decrypt_string.feature +13 -0
- data/features/decryption.feature +17 -0
- data/features/encryption.feature +19 -0
- data/features/step_definitions/ruby_gpg_steps.rb +66 -0
- data/features/support/env.rb +12 -0
- data/lib/ruby_gpg.rb +77 -0
- data/spec/ruby_gpg_spec.rb +241 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +9 -0
- data/test_keys/pubring.gpg +0 -0
- data/test_keys/secring.gpg +0 -0
- data/test_keys/trustdb.gpg +0 -0
- metadata +117 -0
data/.autotest
ADDED
data/.gitignore
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
## MAC OS
|
2
|
+
.DS_Store
|
3
|
+
|
4
|
+
## TEXTMATE
|
5
|
+
*.tmproj
|
6
|
+
tmtags
|
7
|
+
|
8
|
+
## EMACS
|
9
|
+
*~
|
10
|
+
\#*
|
11
|
+
.\#*
|
12
|
+
|
13
|
+
## VIM
|
14
|
+
*.swp
|
15
|
+
|
16
|
+
## PROJECT::GENERAL
|
17
|
+
coverage
|
18
|
+
rdoc
|
19
|
+
pkg
|
20
|
+
tmp
|
21
|
+
doc
|
22
|
+
.yardoc
|
23
|
+
*.gemspec
|
24
|
+
|
25
|
+
## PROJECT::SPECIFIC
|
26
|
+
test_keys/random_seed
|
data/CHANGELOG.markdown
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Justin Blake
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.markdown
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# Ruby GPG
|
2
|
+
|
3
|
+
Ruby wrapper for the `gpg` binary. You probably want to be using the
|
4
|
+
`ruby-gpgme` gem instead, but if you can't install the gpgme libraries
|
5
|
+
for some reason, I guess you have to settle for this.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
gem install ruby_gpg
|
10
|
+
|
11
|
+
## Configuration
|
12
|
+
|
13
|
+
# Defaults to "gpg"
|
14
|
+
RubyGpg.config.executable = "/custom/path/to/gpg"
|
15
|
+
|
16
|
+
# Defaults to "~/.gnupg"
|
17
|
+
RubyGpg.config.homedir = "/custom/path/to/home"
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
# creates /path/to/file.gpg:
|
22
|
+
RubyGpg.encrypt("/path/to/file", "Mr. Recipient")
|
23
|
+
|
24
|
+
# creates /path/to/file:
|
25
|
+
RubyGpg.decrypt("/path/to/file.gpg", "passphrase")
|
26
|
+
|
27
|
+
For more details, see the
|
28
|
+
[RDocs](http://rdoc.info/projects/blaix/ruby_gpg).
|
29
|
+
|
30
|
+
## Copyright
|
31
|
+
|
32
|
+
Copyright (c) 2010 Justin Blake. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "gitc-ruby_gpg"
|
8
|
+
gem.summary = %Q{Ruby wrapper for the gpg binary}
|
9
|
+
gem.description = %Q{Ruby wrapper for the gpg binary}
|
10
|
+
gem.email = "itdevelopers@globalitcreations.com"
|
11
|
+
gem.homepage = "http://github.com/gitcapps/ruby_gpg"
|
12
|
+
gem.authors = ["Justin Blake", "Scott Barr", "Divya Bhargov"]
|
13
|
+
gem.add_development_dependency "rspec", ">= 1.2.9"
|
14
|
+
gem.add_development_dependency "yard", ">= 0"
|
15
|
+
gem.add_development_dependency "cucumber", ">= 0"
|
16
|
+
gem.add_development_dependency "mocha", ">= 0.9.8"
|
17
|
+
gem.rubyforge_project = "nowarning"
|
18
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
19
|
+
end
|
20
|
+
Jeweler::GemcutterTasks.new
|
21
|
+
rescue LoadError
|
22
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
23
|
+
end
|
24
|
+
|
25
|
+
require 'spec/rake/spectask'
|
26
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
27
|
+
spec.libs << 'lib' << 'spec'
|
28
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
29
|
+
end
|
30
|
+
|
31
|
+
namespace :spec do
|
32
|
+
Spec::Rake::SpecTask.new(:doc) do |spec|
|
33
|
+
spec.libs << 'lib' << 'spec'
|
34
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
35
|
+
spec.spec_opts << '--format specdoc'
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
40
|
+
spec.libs << 'lib' << 'spec'
|
41
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
42
|
+
spec.rcov = true
|
43
|
+
end
|
44
|
+
|
45
|
+
task :spec => :check_dependencies
|
46
|
+
|
47
|
+
begin
|
48
|
+
require 'cucumber/rake/task'
|
49
|
+
Cucumber::Rake::Task.new(:features)
|
50
|
+
|
51
|
+
task :features => :check_dependencies
|
52
|
+
rescue LoadError
|
53
|
+
task :features do
|
54
|
+
abort "Cucumber is not available. In order to run features, you must: sudo gem install cucumber"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
task :default => :spec
|
59
|
+
|
60
|
+
begin
|
61
|
+
require 'yard'
|
62
|
+
YARD::Rake::YardocTask.new do |y|
|
63
|
+
y.files << '-' << 'CHANGELOG.*' << 'TODO.*'
|
64
|
+
end
|
65
|
+
rescue LoadError
|
66
|
+
task :yardoc do
|
67
|
+
abort "YARD is not available. In order to run yardoc, you must: sudo gem install yard"
|
68
|
+
end
|
69
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.2.0
|
data/cucumber.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
default: features
|
@@ -0,0 +1,13 @@
|
|
1
|
+
Feature: Decrypt String
|
2
|
+
In order to read an encrypted string
|
3
|
+
As a user
|
4
|
+
I want to decrypt it
|
5
|
+
|
6
|
+
Scenario: Decrypt with proper recipient/recipient
|
7
|
+
Given a key pair for Slow Joe Crow with passphrase test
|
8
|
+
And a file named "secrets" containing "some content"
|
9
|
+
And I encrypt the file "secrets" for "Slow Joe Crow"
|
10
|
+
And I read the file "secrets.gpg" to a string
|
11
|
+
And the string should not be "secrets"
|
12
|
+
When I decrypt the string with passphrase "test"
|
13
|
+
Then the string should be "secrets"
|
@@ -0,0 +1,17 @@
|
|
1
|
+
Feature: Decryption
|
2
|
+
In order to read an encrypted file
|
3
|
+
As a user
|
4
|
+
I want to decrypt it
|
5
|
+
|
6
|
+
Background:
|
7
|
+
Given a file named "secrets" containing "some content"
|
8
|
+
And a key pair for Slow Joe Crow with passphrase test
|
9
|
+
|
10
|
+
Scenario: Decrypt with proper recipient/recipient
|
11
|
+
Given I encrypt the file "secrets" for "Slow Joe Crow"
|
12
|
+
And the file "secrets" does not exist
|
13
|
+
When I decrypt the file "secrets.gpg" with passphrase "test"
|
14
|
+
Then the file "secrets" should exist
|
15
|
+
And the file "secrets" should contain "some content"
|
16
|
+
|
17
|
+
# TODO: Scenario for failed decrypt (bad recipient and bad passprhase)
|
@@ -0,0 +1,19 @@
|
|
1
|
+
Feature: Encryption
|
2
|
+
In order to keep a file private
|
3
|
+
As a user
|
4
|
+
I want to encrypt the file
|
5
|
+
|
6
|
+
Background:
|
7
|
+
Given a key pair for Slow Joe Crow with passphrase test
|
8
|
+
And a file named "secrets" containing "some content"
|
9
|
+
And the file "secrets.gpg" does not exist
|
10
|
+
|
11
|
+
Scenario: Encrypt
|
12
|
+
When I encrypt the file "secrets" for "Slow Joe Crow"
|
13
|
+
Then the file "secrets.gpg" should exist
|
14
|
+
And the file "secrets.gpg" should not contain "some content"
|
15
|
+
|
16
|
+
Scenario: Unknown recipient
|
17
|
+
When I try to encrypt the file "secrets" for "Sue"
|
18
|
+
Then the command should raise an error matching "key not found"
|
19
|
+
And the file "secrets.gpg" should not exist
|
@@ -0,0 +1,66 @@
|
|
1
|
+
Given /^a key pair for Slow Joe Crow with passphrase test$/ do
|
2
|
+
# Already built keys in spec/gpg_home. Tell RubyGpg to use this...
|
3
|
+
RubyGpg.config.homedir = File.dirname(__FILE__) + '/../../test_keys'
|
4
|
+
end
|
5
|
+
|
6
|
+
Given /^a file named "([^\"]*)" containing "([^\"]*)"$/ do |filename, content|
|
7
|
+
File.open("#{TMP_PATH}/#{filename}", 'w') do |f|
|
8
|
+
f.write(content)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
Given /^the file "([^\"]*)" does not exist$/ do |filename|
|
13
|
+
if File.exist?("#{TMP_PATH}/#{filename}")
|
14
|
+
File.delete("#{TMP_PATH}/#{filename}")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
Given /^I read the file "([^\"]*)" to a string$/ do |filename|
|
19
|
+
@string = File.read("#{TMP_PATH}/#{filename}")
|
20
|
+
end
|
21
|
+
|
22
|
+
Given /^the string should not be "([^\"]*)"$/ do |string|
|
23
|
+
@string.strip.should_not == string.strip
|
24
|
+
end
|
25
|
+
|
26
|
+
When /^I encrypt the file "([^\"]*)" for "([^\"]*)"$/ do |filename, recipient|
|
27
|
+
RubyGpg.encrypt("#{TMP_PATH}/#{filename}", recipient)
|
28
|
+
end
|
29
|
+
|
30
|
+
When /^I try to encrypt the file "([^\"]*)" for "([^\"]*)"$/ do |filename, recipient|
|
31
|
+
@command = lambda {
|
32
|
+
RubyGpg.encrypt("#{TMP_PATH}/#{filename}", recipient)
|
33
|
+
}
|
34
|
+
end
|
35
|
+
|
36
|
+
When /^I decrypt the file "([^\"]*)" with passphrase "([^\"]*)"$/ do |filename, passphrase|
|
37
|
+
RubyGpg.decrypt("#{TMP_PATH}/#{filename}", passphrase)
|
38
|
+
end
|
39
|
+
|
40
|
+
When /^I decrypt the string with passphrase "([^\"]*)"$/ do |passphrase|
|
41
|
+
@string = RubyGpg.decrypt_string(@string, passphrase)
|
42
|
+
end
|
43
|
+
|
44
|
+
Then /^the command should raise an error matching "([^\"]*)"$/ do |error|
|
45
|
+
@command.should raise_error(/#{Regexp.escape(error)}/)
|
46
|
+
end
|
47
|
+
|
48
|
+
Then /^the file "([^\"]*)" should exist$/ do |filename|
|
49
|
+
File.exist?("#{TMP_PATH}/#{filename}").should be_true
|
50
|
+
end
|
51
|
+
|
52
|
+
Then /^the file "([^\"]*)" should not exist$/ do |filename|
|
53
|
+
File.exist?("#{TMP_PATH}/#{filename}").should_not be_true
|
54
|
+
end
|
55
|
+
|
56
|
+
Then /^the file "([^\"]*)" should not contain "([^\"]*)"$/ do |filename, content|
|
57
|
+
File.read("#{TMP_PATH}/#{filename}").should_not include(content)
|
58
|
+
end
|
59
|
+
|
60
|
+
Then /^the file "([^\"]*)" should contain "([^\"]*)"$/ do |filename, content|
|
61
|
+
File.read("#{TMP_PATH}/#{filename}").should include(content)
|
62
|
+
end
|
63
|
+
|
64
|
+
Then /^the string should be "([^\"]*)"$/ do |string|
|
65
|
+
string.strip.should == string.strip
|
66
|
+
end
|
data/lib/ruby_gpg.rb
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'open3'
|
2
|
+
|
3
|
+
module RubyGpg
|
4
|
+
extend self
|
5
|
+
|
6
|
+
Config = Struct.new(:executable, :homedir)
|
7
|
+
def config
|
8
|
+
@config ||= Config.new("gpg", "~/.gnupg")
|
9
|
+
end
|
10
|
+
|
11
|
+
def gpg_command
|
12
|
+
"#{config.executable} --homedir #{config.homedir} --quiet" +
|
13
|
+
" --no-secmem-warning --no-permission-warning --no-tty --yes"
|
14
|
+
end
|
15
|
+
|
16
|
+
def encrypt(file, recipient, opts = {})
|
17
|
+
options = {
|
18
|
+
:armor => false
|
19
|
+
}.merge(opts)
|
20
|
+
|
21
|
+
output = output_filename(file, options)
|
22
|
+
|
23
|
+
ascii = options[:armor] == true ? "-a " : ""
|
24
|
+
|
25
|
+
command = "#{gpg_command} #{ascii}--output #{output}" +
|
26
|
+
" --recipient \"#{recipient}\" --encrypt #{file}"
|
27
|
+
|
28
|
+
run_command(command)
|
29
|
+
end
|
30
|
+
|
31
|
+
# Encrypt a string from stdin
|
32
|
+
def encrypt_string(string, recipient, opts = {})
|
33
|
+
command = gpg_command.dup
|
34
|
+
command << " -a" if opts[:armor]
|
35
|
+
command << " --encrypt"
|
36
|
+
command << " --recipient \"#{recipient}\""
|
37
|
+
run_command(command, string)
|
38
|
+
end
|
39
|
+
|
40
|
+
def decrypt(file, passphrase = nil, opts = {})
|
41
|
+
outfile = opts[:output].nil? ? file.gsub(/\.gpg$|\.asc$/, '') : opts[:output]
|
42
|
+
command = "#{gpg_command} --output #{outfile}"
|
43
|
+
command << " --passphrase #{passphrase}" if passphrase
|
44
|
+
command << " --decrypt #{file}"
|
45
|
+
run_command(command)
|
46
|
+
end
|
47
|
+
|
48
|
+
def decrypt_string(string, passphrase = nil)
|
49
|
+
command = gpg_command.dup
|
50
|
+
command << " --passphrase #{passphrase}" if passphrase
|
51
|
+
command << " --decrypt"
|
52
|
+
run_command(command, string)
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def run_command(command, input = nil)
|
58
|
+
output = ""
|
59
|
+
Open3.popen3(command) do |stdin, stdout, stderr|
|
60
|
+
stdin.write(input) if input
|
61
|
+
stdin.close_write
|
62
|
+
output << stdout.read
|
63
|
+
error = stderr.read
|
64
|
+
if error && !error.empty?
|
65
|
+
raise "GPG command (#{command}) failed with: #{error}"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
output
|
69
|
+
end
|
70
|
+
|
71
|
+
# Return the output filename to use
|
72
|
+
def output_filename(file, opts)
|
73
|
+
extension = opts[:armor] ? "asc" : "gpg"
|
74
|
+
opts[:output].nil? ? "#{file}.#{extension}" : opts[:output]
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
@@ -0,0 +1,241 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "RubyGpg" do
|
4
|
+
def expect_command_to_match(part_of_command)
|
5
|
+
Open3.expects(:popen3).with do |command|
|
6
|
+
case part_of_command
|
7
|
+
when Regexp: command =~ part_of_command
|
8
|
+
when String: command.include?(part_of_command)
|
9
|
+
else raise "Can't match that"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def stub_error(error_message)
|
15
|
+
@stderr.write(error_message)
|
16
|
+
@stderr.rewind
|
17
|
+
end
|
18
|
+
|
19
|
+
before do
|
20
|
+
@stdin = StringIO.new
|
21
|
+
@stdout = StringIO.new
|
22
|
+
@stderr = StringIO.new
|
23
|
+
Open3.stubs(:popen3).yields(@stdin, @stdout, @stderr)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "allows the use of a custom path to the gpg executable" do
|
27
|
+
RubyGpg.config.executable = "/custom/path/to/gpg"
|
28
|
+
RubyGpg.gpg_command.should =~ /^\/custom\/path\/to\/gpg/
|
29
|
+
end
|
30
|
+
|
31
|
+
it "allows the use of a custom gpg home directory" do
|
32
|
+
RubyGpg.config.homedir = "/custom/path/to/home"
|
33
|
+
RubyGpg.gpg_command.should include("--homedir /custom/path/to/home")
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should run with sane, headless defaults" do
|
37
|
+
command = RubyGpg.gpg_command
|
38
|
+
command.should include("--no-secmem-warning")
|
39
|
+
command.should include("--no-permission-warning")
|
40
|
+
command.should include("--no-tty")
|
41
|
+
command.should include("--quiet")
|
42
|
+
command.should include("--yes")
|
43
|
+
end
|
44
|
+
|
45
|
+
describe '.encrypt(filename, recipient)' do
|
46
|
+
def run_encrypt
|
47
|
+
RubyGpg.encrypt('filename', 'recipient')
|
48
|
+
end
|
49
|
+
|
50
|
+
it "uses the configured gpg command" do
|
51
|
+
expect_command_to_match(/^#{Regexp.escape(RubyGpg.gpg_command)}/)
|
52
|
+
run_encrypt
|
53
|
+
end
|
54
|
+
|
55
|
+
it "issues an encrypt command to gpg" do
|
56
|
+
expect_command_to_match("--encrypt")
|
57
|
+
run_encrypt
|
58
|
+
end
|
59
|
+
|
60
|
+
it "issues the encrypt command for the passed filename" do
|
61
|
+
expect_command_to_match(/filename$/)
|
62
|
+
run_encrypt
|
63
|
+
end
|
64
|
+
|
65
|
+
it "issues the encrypts command for the passed recipient" do
|
66
|
+
expect_command_to_match("--recipient \"recipient\"")
|
67
|
+
run_encrypt
|
68
|
+
end
|
69
|
+
|
70
|
+
it "saves encrypted version to filename.gpg" do
|
71
|
+
expect_command_to_match("--output filename.gpg")
|
72
|
+
run_encrypt
|
73
|
+
end
|
74
|
+
|
75
|
+
it "raises any errors from gpg" do
|
76
|
+
stub_error("error message")
|
77
|
+
lambda { run_encrypt }.should raise_error(/GPG command \(.*gpg.*--encrypt.*filename\) failed with: error message/)
|
78
|
+
end
|
79
|
+
|
80
|
+
it "does not raise if there is no output from gpg" do
|
81
|
+
lambda { run_encrypt }.should_not raise_error
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe '.encrypt(filename, recipient, opts) with armor specified' do
|
86
|
+
def run_encrypt
|
87
|
+
RubyGpg.encrypt('filename', 'recipient', {:armor => true})
|
88
|
+
end
|
89
|
+
|
90
|
+
it "saves armored version to filename.asc" do
|
91
|
+
expect_command_to_match("-a --output filename.asc")
|
92
|
+
run_encrypt
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
describe '.encrypt(filename, recipient, opts) with ascii output file specified' do
|
97
|
+
def run_encrypt
|
98
|
+
RubyGpg.encrypt('filename', 'recipient', {:armor => true, :output => "foo.asc"})
|
99
|
+
end
|
100
|
+
|
101
|
+
it "saves armored version to foo.asc" do
|
102
|
+
expect_command_to_match("-a --output foo.asc")
|
103
|
+
run_encrypt
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
describe '.encrypt_string(string, recipient, opts)' do
|
108
|
+
def run_encrypt_string
|
109
|
+
RubyGpg.encrypt_string("string to encrypt", "recipient")
|
110
|
+
end
|
111
|
+
|
112
|
+
it "uses the configured gpg command" do
|
113
|
+
expect_command_to_match(/^#{Regexp.escape(RubyGpg.gpg_command)}/)
|
114
|
+
run_encrypt_string
|
115
|
+
end
|
116
|
+
|
117
|
+
it "issues an encrypt command to gpg" do
|
118
|
+
expect_command_to_match("--encrypt")
|
119
|
+
run_encrypt_string
|
120
|
+
end
|
121
|
+
|
122
|
+
it "issues the encrypts command for the passed recipient" do
|
123
|
+
expect_command_to_match("--recipient \"recipient\"")
|
124
|
+
run_encrypt_string
|
125
|
+
end
|
126
|
+
|
127
|
+
it "sends the passed string as stdin" do
|
128
|
+
@stdin.expects(:write).with('string to encrypt')
|
129
|
+
run_encrypt_string
|
130
|
+
end
|
131
|
+
|
132
|
+
it "returns the encrypted string" do
|
133
|
+
@stdout.write("encrypted string")
|
134
|
+
@stdout.rewind
|
135
|
+
run_encrypt_string.should == "encrypted string"
|
136
|
+
end
|
137
|
+
|
138
|
+
end
|
139
|
+
|
140
|
+
describe '.decrypt(filename)' do
|
141
|
+
def run_decrypt(passphrase = nil)
|
142
|
+
RubyGpg.decrypt('filename.gpg', passphrase)
|
143
|
+
end
|
144
|
+
|
145
|
+
it "uses the configured gpg command" do
|
146
|
+
expect_command_to_match(/^#{Regexp.escape(RubyGpg.gpg_command)}/)
|
147
|
+
run_decrypt
|
148
|
+
end
|
149
|
+
|
150
|
+
it "issues a decrypt command to gpg" do
|
151
|
+
expect_command_to_match("--decrypt")
|
152
|
+
run_decrypt
|
153
|
+
end
|
154
|
+
|
155
|
+
it "accepts an optional passphrase" do
|
156
|
+
expect_command_to_match("--passphrase secret")
|
157
|
+
run_decrypt("secret")
|
158
|
+
end
|
159
|
+
|
160
|
+
it "issues the decrypt command for the passed filename" do
|
161
|
+
expect_command_to_match(/filename\.gpg$/)
|
162
|
+
run_decrypt
|
163
|
+
end
|
164
|
+
|
165
|
+
it "saves decrypted version to filename without .gpg extension" do
|
166
|
+
# Note the space after "filename". Without the space it is possible that
|
167
|
+
# the file extention still exists
|
168
|
+
expect_command_to_match("--output filename ")
|
169
|
+
run_decrypt
|
170
|
+
end
|
171
|
+
|
172
|
+
it "raises any errors from gpg" do
|
173
|
+
stub_error("error message")
|
174
|
+
lambda { run_decrypt }.should raise_error(/GPG command \(.*gpg.*--decrypt.*filename\.gpg\) failed with: error message/)
|
175
|
+
end
|
176
|
+
|
177
|
+
it "does not raise if there is no output from gpg" do
|
178
|
+
lambda { run_decrypt }.should_not raise_error
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
describe '.decrypt(filename) for asc file' do
|
183
|
+
def run_decrypt(passphrase = nil, opts = {})
|
184
|
+
RubyGpg.decrypt('filename.asc', passphrase, opts)
|
185
|
+
end
|
186
|
+
|
187
|
+
it "issues the decrypt command for the ascii filename" do
|
188
|
+
# Note the space after "filename". Without the space it is possible that
|
189
|
+
# the file extention still exists
|
190
|
+
expect_command_to_match("--output filename ")
|
191
|
+
run_decrypt
|
192
|
+
end
|
193
|
+
|
194
|
+
it "issues the decrypt command for the filename passed in options" do
|
195
|
+
expect_command_to_match("--output foo.txt ")
|
196
|
+
run_decrypt(nil, {:output => "foo.txt"})
|
197
|
+
end
|
198
|
+
|
199
|
+
end
|
200
|
+
|
201
|
+
describe '.decrypt_string(string)' do
|
202
|
+
def run_decrypt_string(passphrase = nil)
|
203
|
+
RubyGpg.decrypt_string('encrypted string', passphrase)
|
204
|
+
end
|
205
|
+
|
206
|
+
it "uses the configured gpg command" do
|
207
|
+
expect_command_to_match(/^#{Regexp.escape(RubyGpg.gpg_command)}/)
|
208
|
+
run_decrypt_string
|
209
|
+
end
|
210
|
+
|
211
|
+
it "issues a decrypt command to gpg" do
|
212
|
+
expect_command_to_match("--decrypt")
|
213
|
+
run_decrypt_string
|
214
|
+
end
|
215
|
+
|
216
|
+
it "accepts an optional passphrase" do
|
217
|
+
expect_command_to_match("--passphrase secret")
|
218
|
+
run_decrypt_string("secret")
|
219
|
+
end
|
220
|
+
|
221
|
+
it "sends the passed string as stdin" do
|
222
|
+
@stdin.expects(:write).with("encrypted string")
|
223
|
+
run_decrypt_string
|
224
|
+
end
|
225
|
+
|
226
|
+
it "returns the decrypted string" do
|
227
|
+
@stdout.write("decrypted string")
|
228
|
+
@stdout.rewind
|
229
|
+
run_decrypt_string.should == "decrypted string"
|
230
|
+
end
|
231
|
+
|
232
|
+
it "raises any errors from gpg" do
|
233
|
+
stub_error("error message")
|
234
|
+
lambda { run_decrypt_string }.should raise_error(/GPG command \(.*gpg.*--decrypt.*\) failed with: error message/)
|
235
|
+
end
|
236
|
+
|
237
|
+
it "does not raise if there is no output from gpg" do
|
238
|
+
lambda { run_decrypt_string }.should_not raise_error
|
239
|
+
end
|
240
|
+
end
|
241
|
+
end
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/spec/spec_helper.rb
ADDED
Binary file
|
Binary file
|
Binary file
|
metadata
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gitc-ruby_gpg
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Justin Blake
|
8
|
+
- Scott Barr
|
9
|
+
- Divya Bhargov
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
|
14
|
+
date: 2010-07-16 00:00:00 +08:00
|
15
|
+
default_executable:
|
16
|
+
dependencies:
|
17
|
+
- !ruby/object:Gem::Dependency
|
18
|
+
name: rspec
|
19
|
+
type: :development
|
20
|
+
version_requirement:
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
requirements:
|
23
|
+
- - ">="
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: 1.2.9
|
26
|
+
version:
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: yard
|
29
|
+
type: :development
|
30
|
+
version_requirement:
|
31
|
+
version_requirements: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: "0"
|
36
|
+
version:
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: cucumber
|
39
|
+
type: :development
|
40
|
+
version_requirement:
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: "0"
|
46
|
+
version:
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: mocha
|
49
|
+
type: :development
|
50
|
+
version_requirement:
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 0.9.8
|
56
|
+
version:
|
57
|
+
description: Ruby wrapper for the gpg binary
|
58
|
+
email: itdevelopers@globalitcreations.com
|
59
|
+
executables: []
|
60
|
+
|
61
|
+
extensions: []
|
62
|
+
|
63
|
+
extra_rdoc_files:
|
64
|
+
- LICENSE
|
65
|
+
- README.markdown
|
66
|
+
files:
|
67
|
+
- .autotest
|
68
|
+
- .gitignore
|
69
|
+
- CHANGELOG.markdown
|
70
|
+
- LICENSE
|
71
|
+
- README.markdown
|
72
|
+
- Rakefile
|
73
|
+
- VERSION
|
74
|
+
- cucumber.yml
|
75
|
+
- features/decrypt_string.feature
|
76
|
+
- features/decryption.feature
|
77
|
+
- features/encryption.feature
|
78
|
+
- features/step_definitions/ruby_gpg_steps.rb
|
79
|
+
- features/support/env.rb
|
80
|
+
- lib/ruby_gpg.rb
|
81
|
+
- spec/ruby_gpg_spec.rb
|
82
|
+
- spec/spec.opts
|
83
|
+
- spec/spec_helper.rb
|
84
|
+
- test_keys/pubring.gpg
|
85
|
+
- test_keys/secring.gpg
|
86
|
+
- test_keys/trustdb.gpg
|
87
|
+
has_rdoc: true
|
88
|
+
homepage: http://github.com/gitcapps/ruby_gpg
|
89
|
+
licenses: []
|
90
|
+
|
91
|
+
post_install_message:
|
92
|
+
rdoc_options:
|
93
|
+
- --charset=UTF-8
|
94
|
+
require_paths:
|
95
|
+
- lib
|
96
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: "0"
|
101
|
+
version:
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: "0"
|
107
|
+
version:
|
108
|
+
requirements: []
|
109
|
+
|
110
|
+
rubyforge_project: nowarning
|
111
|
+
rubygems_version: 1.3.5
|
112
|
+
signing_key:
|
113
|
+
specification_version: 3
|
114
|
+
summary: Ruby wrapper for the gpg binary
|
115
|
+
test_files:
|
116
|
+
- spec/ruby_gpg_spec.rb
|
117
|
+
- spec/spec_helper.rb
|