ftpmvc-gpg 0.0.1 → 0.0.2

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: 5392adeeee961dafdcf2102567bcef7afd0e1992
4
- data.tar.gz: ccf073afb1e1ea1dd5c8ff03febfbbbaddae3f3d
3
+ metadata.gz: 50a59f07de59922eb4c215c482310d8eb7f5d3e1
4
+ data.tar.gz: 1973f0ab9a0ab9f33628095db7e052f4b20f2c76
5
5
  SHA512:
6
- metadata.gz: 107da1310efc682b26e039b35ac5ee3e400960234553c188b1329544e3ab10fe164fc0c77a9c8ff7a5d8c2675373e34b2da6adc9cf7d6c8915092acf7c8a00ea
7
- data.tar.gz: 2376cc2c89afbf172d0ebf754795de001f957c8027d91e509687da25cf94d230ccda531dbedff4dbf9f7e224d34ceb9b2e5e477ae1ff00c5553848ecaa0c2a66
6
+ metadata.gz: f048d6ce39248a31866a1b8ecea1f9fe3040f6c9971d92030301d9e109e126ee32cac71b955b83dbeeb294b1caab115382ebd9c35b34d5ca339e7eb1b5e145ac
7
+ data.tar.gz: 5c2a0859a5e66affb19e661b99e966e07c961e7b5a9a3898041c9279e77b0256f348aaaae3e0fb4053d343de44dcd8a77a3bd37ba04f9a4b67714b9ce6ffc4f2
@@ -6,7 +6,8 @@ module FTPMVC
6
6
  class Filter < FTPMVC::Filter
7
7
  def initialize(fs, chain, options={})
8
8
  super fs, chain
9
- @crypto = GPGME::Crypto.new recipients: options[:recipients]
9
+ @crypto = GPGME::Crypto.new recipients: options[:recipients], always_trust: true
10
+ import_keys(options[:keys]) if options.include?(:keys)
10
11
  end
11
12
 
12
13
  def index(path)
@@ -18,7 +19,31 @@ module FTPMVC
18
19
  end
19
20
 
20
21
  def get(path)
21
- StringIO.new(@crypto.encrypt(GPGME::Data.from_io(@chain.get(path))).read)
22
+ StringIO.new(@crypto.encrypt(original_data(path)).read)
23
+ end
24
+
25
+ def exists?(path)
26
+ @chain.exists?(remove_extension(path))
27
+ end
28
+
29
+ def directory?(path)
30
+ @chain.directory?(remove_extension(path))
31
+ end
32
+
33
+ protected
34
+
35
+ def original_data(path)
36
+ GPGME::Data.from_io(@chain.get(remove_extension(path)))
37
+ end
38
+
39
+ def import_keys(keys)
40
+ keys.each do |key|
41
+ GPGME::Key.import(key.gsub(/^\s*/, ''))
42
+ end
43
+ end
44
+
45
+ def remove_extension(path)
46
+ path.gsub(/\.gpg$/, '')
22
47
  end
23
48
  end
24
49
  end
@@ -1,5 +1,5 @@
1
1
  module FTPMVC
2
2
  module GPG
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
data/lib/ftpmvc/gpg.rb CHANGED
@@ -1,7 +1,2 @@
1
1
  require 'ftpmvc/gpg/version'
2
2
  require 'ftpmvc/gpg/filter'
3
-
4
- module FTPMVC
5
- module GPG
6
- end
7
- end
@@ -8,7 +8,29 @@ describe FTPMVC::GPG::Filter do
8
8
  let(:app) do
9
9
  FTPMVC::Application.new do
10
10
 
11
- filter FTPMVC::GPG::Filter, recipients: 'john.doe@gmail.com'
11
+ filter FTPMVC::GPG::Filter, recipients: ['john.doe@gmail.com'], keys: [
12
+ <<-EOF
13
+ -----BEGIN PGP PUBLIC KEY BLOCK-----
14
+ Version: GnuPG v1
15
+
16
+ mI0EVGNdYQEEALR159b8du6QsH0lQDx1ImFmdN9qVWHgbcXDK4CKwXMbLwNEsjIn
17
+ LNkGP7ZPtnvodywlV7G+CDcVDa2r7MrLJdk3/idQ25zBVnL8HndkZiEZHj+WEo5u
18
+ sR5uZQSshGjWdl2UKWOJoRCW0PEfNBxJeKbCrksaebXjzgXIJl7Mar6TABEBAAG0
19
+ HUpvaG4gRG9lIDxqb2huLmRvZUBnbWFpbC5jb20+iLgEEwECACIFAlRjXWECGwMG
20
+ CwkIBwMCBhUIAgkKCwQWAgMBAh4BAheAAAoJEGp4Yp2MJm5hxOQD/jGvwPiKEgHK
21
+ AKUqzMv8RpkfP+hkNMa+clhURYRReo0ISWDsb8XUZsZF84ZhwVshlAHqCVdJb13H
22
+ iK/uSBJpxgEHwzIIn+k1G14HK7DKC7kfheaN0mvS3Tq9sdd5PyWGnQyBiP3OYlmF
23
+ TWa/KEz5IfKs95nSBa1w3Vc9cjpn1YgxuI0EVGNdYQEEALZkxWWXptwEcdtYwdR6
24
+ wgXbmFKjeyhRutGJoAR/SwkDoQBqQhTLh6eFKTL9gHWolAJJm4H0pBwVGsVa5su8
25
+ wXfgIu2Y3rSItwjvof05mlTdqjaMVYM/jiHnfIBVJa/xuQRhkroa1jlK4iVZmKNY
26
+ 8qsj6pvKGB0uOj+BHMMnMMz5ABEBAAGInwQYAQIACQUCVGNdYQIbDAAKCRBqeGKd
27
+ jCZuYcXBBACtBmIR5o/m2adUCzYfb/mNlh7eM/bvNMeXXmPsazhl5kp05izqy5Z1
28
+ iSQTnoJ8FKi4ke9GRbpKL4EZ4tWop4QKWAbbojIepR0Q6Ncvv4Ho9N32nmSEEfBU
29
+ UPgZz+71ilscZiuigmFSDhP368qBG6rmaxgOoK4O+wjVJEJzq4Yc8A==
30
+ =NH17
31
+ -----END PGP PUBLIC KEY BLOCK-----
32
+ EOF
33
+ ]
12
34
 
13
35
  filesystem do
14
36
  directory :encrypted
@@ -40,7 +62,7 @@ describe FTPMVC::GPG::Filter do
40
62
  it 'encrypts files content' do
41
63
  with_application(app) do |ftp|
42
64
  ftp.login
43
- expect(get(ftp, '/encrypted/password.txt.gpg').size).to eq 342
65
+ expect(get(ftp, '/encrypted/password.txt.gpg').size).to eq 213
44
66
  end
45
67
  end
46
68
  end
@@ -37,13 +37,59 @@ describe FTPMVC::GPG::Filter do
37
37
 
38
38
  describe '#get' do
39
39
  before do
40
+ allow_any_instance_of(GPGME::Crypto)
41
+ .to receive(:encrypt)
42
+ .and_return StringIO.new('encrypted secret')
40
43
  allow(other_filter)
41
44
  .to receive(:get)
42
45
  .and_return StringIO.new('secret')
43
46
  end
44
47
  it 'encrypts original content' do
45
- expect(gpg_filter.get('/file.txt.gpg').read.size).to eq 342
48
+ expect(gpg_filter.get('/file.txt.gpg').read).to eq 'encrypted secret'
46
49
  end
47
50
 
51
+ describe '#initialize' do
52
+ context 'when keys option is given' do
53
+ it 'imports the keys' do
54
+ expect(GPGME::Key).to receive(:import).twice
55
+ FTPMVC::GPG::Filter.new(nil,
56
+ other_filter,
57
+ recipients: 'john.doe@gmail.com',
58
+ keys: ['mykey1', 'mykey2'])
59
+ end
60
+ end
61
+ context 'when key has indentation' do
62
+ it 'removes indentation' do
63
+ expect(GPGME::Key)
64
+ .to receive(:import)
65
+ .with("-----BEGIN PGP PUBLIC KEY BLOCK-----\n...\n-----END PGP PUBLIC KEY BLOCK-----\n")
66
+ FTPMVC::GPG::Filter.new(nil, other_filter, recipients: 'john.doe@gmail.com', keys: [
67
+ <<-EOF
68
+ -----BEGIN PGP PUBLIC KEY BLOCK-----
69
+ ...
70
+ -----END PGP PUBLIC KEY BLOCK-----
71
+ EOF
72
+ ])
73
+ end
74
+ end
75
+ end
76
+
77
+ describe '#exists?' do
78
+ it 'removes .gpg extension from filename' do
79
+ expect(other_filter)
80
+ .to receive(:exists?)
81
+ .with('/secret/passwords.txt')
82
+ gpg_filter.exists?('/secret/passwords.txt.gpg')
83
+ end
84
+ end
85
+
86
+ describe '#directory?' do
87
+ it 'removes .gpg extension from filename' do
88
+ expect(other_filter)
89
+ .to receive(:directory?)
90
+ .with('/secret/passwords.txt')
91
+ gpg_filter.directory?('/secret/passwords.txt.gpg')
92
+ end
93
+ end
48
94
  end
49
95
  end
metadata CHANGED
@@ -1,83 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ftpmvc-gpg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - André Aizim Kelmanson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-28 00:00:00.000000000 Z
11
+ date: 2014-11-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.6'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.6'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: guard-rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: ftpmvc
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: gpgme
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '>='
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  description: FTPMVC filter to encrypt/decrypt files
@@ -87,9 +87,9 @@ executables: []
87
87
  extensions: []
88
88
  extra_rdoc_files: []
89
89
  files:
90
- - .gitignore
91
- - .rspec
92
- - .travis.yml
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
93
  - Gemfile
94
94
  - Guardfile
95
95
  - LICENSE.txt
@@ -112,12 +112,12 @@ require_paths:
112
112
  - lib
113
113
  required_ruby_version: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - '>='
115
+ - - ">="
116
116
  - !ruby/object:Gem::Version
117
117
  version: '0'
118
118
  required_rubygems_version: !ruby/object:Gem::Requirement
119
119
  requirements:
120
- - - '>='
120
+ - - ">="
121
121
  - !ruby/object:Gem::Version
122
122
  version: '0'
123
123
  requirements: []