encrypted_s3_copy 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a1db1a92b7e71921418d741955f587f385a8457a
4
- data.tar.gz: 7314aca977b747a6d04b59b39d897a5d14b9ef4b
3
+ metadata.gz: a06c2294f21fd31b07ad1b0b95b961d39d62371e
4
+ data.tar.gz: 0ccccf1558ac75dd24ad87dd7b2c989edc28bb9e
5
5
  SHA512:
6
- metadata.gz: 7e60597d7737bdc5cb16e55f34f25b649d0abb21f5b6ae3e507084bcb2ecd471e4be1c44967cf63e93a5febe96f2a4ada9bc14b2ec539188978bb420365930e6
7
- data.tar.gz: a78531638bdd7f2324a81c3a8eb670225c217d72e41fe44c64af75e097f88fcf086a2c5fb85538f7858599e06ba32d3d232383aa9f709ec00d587c32eca88f2d
6
+ metadata.gz: 91e8f1643de3f1f976e64ff3e82e3bfec44da5de899a4f63b2d08ce07f2a62617692a45779973e7adfe40fd3afe7f61edcf812bf6c78bc1b08bacc420e507c62
7
+ data.tar.gz: f5df75b65321814924414644c0582cb4881d83a940d9e2fd7a8ff237729d5cfd58dd4dabba6c742b7b90233faf082093ab65f4feba4c6a53edf715e57b401884
File without changes
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ require 'encrypted_s3_copy'
3
+
4
+ client = EncryptedS3Copy::KeyGenerator.new
5
+ client.execute
@@ -0,0 +1,34 @@
1
+ require 'openssl'
2
+ require 'base64'
3
+ require 'optparse'
4
+
5
+ module EncryptedS3Copy
6
+ class KeyGenerator
7
+
8
+ def parse_arg
9
+ opt = OptionParser.new
10
+ opt.on('-k', '--key-file=KEY_FILE_PATH') do |path|
11
+ @key_file_path = path
12
+ end
13
+ opt.parse(ARGV)
14
+ end
15
+
16
+ def generate_key
17
+ my_key = OpenSSL::Cipher.new("AES-256-ECB").random_key
18
+ encoded = Base64.encode64(my_key)
19
+
20
+ File.write(@key_file_path, encoded)
21
+ File.chmod(0600, @key_file_path)
22
+ end
23
+
24
+ def execute
25
+ parse_arg
26
+ generate_key
27
+ end
28
+ end
29
+ end
30
+
31
+ if $0 == __FILE__
32
+ generator = EncryptedS3Copy::KeyGenerator.new
33
+ generator.execute
34
+ end
@@ -1,3 +1,3 @@
1
1
  module EncryptedS3Copy
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -1,5 +1,6 @@
1
1
  require "encrypted_s3_copy/version"
2
2
  require "encrypted_s3_copy/client"
3
+ require "encrypted_s3_copy/key_generator"
3
4
 
4
5
  module EncryptedS3Copy
5
6
  end
@@ -0,0 +1,86 @@
1
+ require_relative '../../lib/encrypted_s3_copy/key_generator'
2
+
3
+ describe EncryptedS3Copy::KeyGenerator do
4
+ describe '#parse_arg' do
5
+ let(:optparse_double) {
6
+ double('double of OptionParser instance').as_null_object
7
+ }
8
+
9
+ before :each do
10
+ allow(OptionParser).to receive(:new).and_return(optparse_double)
11
+ allow(OptionParser).to receive(:on)
12
+ end
13
+
14
+ it 'should prepare parse key file argument' do
15
+ expect(optparse_double).to receive(:on).
16
+ with('-k', '--key-file=KEY_FILE_PATH')
17
+
18
+ subject.parse_arg
19
+ end
20
+ it 'should set key file path argument to instance variable' do
21
+ expected_path = 'a_path'
22
+ allow(optparse_double).to receive(:on).
23
+ with('-k', '--key-file=KEY_FILE_PATH').and_yield(expected_path)
24
+ subject.parse_arg
25
+
26
+ actual = subject.instance_variable_get(:@key_file_path)
27
+ expect(actual).to eq(expected_path)
28
+ end
29
+ it 'should parse args' do
30
+ expect(optparse_double).to receive(:parse)
31
+ subject.parse_arg
32
+ end
33
+ end
34
+
35
+ describe '#generate_key' do
36
+ let(:cipher_double) { double('double of OpenSSL::Cipher instance') }
37
+ let(:random_key_double) { double('double of random key') }
38
+ let(:encoded_key_double) { double('double of encoded key string') }
39
+
40
+ before :each do
41
+ allow(File).to receive(:write)
42
+ allow(File).to receive(:chmod)
43
+ allow(OpenSSL::Cipher).to receive(:new).and_return(cipher_double)
44
+ allow(cipher_double).to receive(:random_key).and_return(random_key_double)
45
+ allow(Base64).to receive(:encode64).and_return(encoded_key_double)
46
+ end
47
+
48
+ it 'should create OpenSSL::Cipher instance' do
49
+ expect(OpenSSL::Cipher).to receive(:new).with("AES-256-ECB").
50
+ and_return(cipher_double)
51
+ subject.generate_key
52
+ end
53
+ it 'should create random key' do
54
+ expect(cipher_double).to receive(:random_key)
55
+ subject.generate_key
56
+ end
57
+
58
+ context 'after generate key' do
59
+ before :each do
60
+ subject.instance_variable_set(:@key_file_path, 'input_path')
61
+ end
62
+
63
+ it 'shuold Base64 encode random key' do
64
+ expect(Base64).to receive(:encode64).with(random_key_double)
65
+ subject.generate_key
66
+ end
67
+ it 'should write key to file' do
68
+ expect(File).to receive(:write).with('input_path', encoded_key_double)
69
+ subject.generate_key
70
+ end
71
+ it 'should set secret file permission' do
72
+ expect(File).to receive(:chmod).with(0600, 'input_path')
73
+ subject.generate_key
74
+ end
75
+
76
+ end
77
+ end
78
+
79
+ describe '#execute' do
80
+ it 'should call parse_arg and generate_key method' do
81
+ expect(subject).to receive(:parse_arg).ordered
82
+ expect(subject).to receive(:generate_key).ordered
83
+ subject.execute
84
+ end
85
+ end
86
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: encrypted_s3_copy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - nabewata07
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-29 00:00:00.000000000 Z
11
+ date: 2014-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk
@@ -71,6 +71,7 @@ email:
71
71
  - channel.momo@gmail.com
72
72
  executables:
73
73
  - encrypted_s3_copy
74
+ - generate_symmetric_key
74
75
  extensions: []
75
76
  extra_rdoc_files: []
76
77
  files:
@@ -83,11 +84,14 @@ files:
83
84
  - README.md
84
85
  - Rakefile
85
86
  - bin/encrypted_s3_copy
87
+ - bin/generate_symmetric_key
86
88
  - encrypted_s3_copy.gemspec
87
89
  - lib/encrypted_s3_copy.rb
88
90
  - lib/encrypted_s3_copy/client.rb
91
+ - lib/encrypted_s3_copy/key_generator.rb
89
92
  - lib/encrypted_s3_copy/version.rb
90
93
  - spec/encrypted_s3_copy/client_spec.rb
94
+ - spec/encrypted_s3_copy/key_generator_spec.rb
91
95
  - spec/encrypted_s3_copy_spec.rb
92
96
  - spec/spec_helper.rb
93
97
  homepage: https://github.com/nabewata07/encrypted_s3_copy
@@ -110,11 +114,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
110
114
  version: '0'
111
115
  requirements: []
112
116
  rubyforge_project:
113
- rubygems_version: 2.0.2
117
+ rubygems_version: 2.2.2
114
118
  signing_key:
115
119
  specification_version: 4
116
120
  summary: upload and download encrypted files to/from AWS S3
117
121
  test_files:
118
122
  - spec/encrypted_s3_copy/client_spec.rb
123
+ - spec/encrypted_s3_copy/key_generator_spec.rb
119
124
  - spec/encrypted_s3_copy_spec.rb
120
125
  - spec/spec_helper.rb