imap-backup 3.2.1 → 3.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 41b597de5360d295f1e974e5014c7b8004749298b4332db083aea95e5aa0815a
4
- data.tar.gz: 95da2ebb094473eae711c85b177b6beb10153cfb1f3074942165599f40d54f63
3
+ metadata.gz: 78b548972cde69ce86be3d23e21dd973730f414b90e5fd0526fd94c2852dc031
4
+ data.tar.gz: d83b2679e25bea24837b3474ce53c5dede5e90e3611b4c2e7374930dc531aa20
5
5
  SHA512:
6
- metadata.gz: 063bcef552b10a3cdff22d7c92346466533bea168b37d258db4277fe8165edb38967194933b5fd1d17cc5a245f721bcd14201f3f6e604092a39ea17fd4002978
7
- data.tar.gz: 9121fda4183536a3a9856ad9fc6e0c1a416d31b44b5dc5e88cb884e3c843cfb668754d2a30fb024399c35aa0137d66ec2143cc2eb5df075b3445120348ae6fd9
6
+ metadata.gz: 419aa2779f25fdb7d34d50b8931a7c77118042082bad3e8d4dcc94a0b5b0a9084d20a684bfe8b8e8b6820f134e3e4f6a3ec0e1d185ad53eb6ccb6ec718f97371
7
+ data.tar.gz: 90a2a552949b4977acd5bbe920de73ac2f39a20bd3c7656dbac1000176d7457c7969305334d9be7e8d3ec8075f292dbbff2901246022dd5e51d65104e507c8df
data/README.md CHANGED
@@ -212,6 +212,12 @@ $ rake
212
212
 
213
213
  To exclude Docker-based tests:
214
214
 
215
+ ```sh
216
+ rake no-docker
217
+ ```
218
+
219
+ or
220
+
215
221
  ```sh
216
222
  $ rspec --tag ~docker
217
223
  ```
data/Rakefile CHANGED
@@ -6,6 +6,12 @@ RSpec::Core::RakeTask.new do |t|
6
6
  t.pattern = "spec/**/*_spec.rb"
7
7
  end
8
8
 
9
+ desc "Run RSpec examples, excluding ones relying on Docker IMAP"
10
+ RSpec::Core::RakeTask.new("no-docker") do |t|
11
+ t.pattern = "spec/**/*_spec.rb"
12
+ t.rspec_opts = "--tag ~docker"
13
+ end
14
+
9
15
  RuboCop::RakeTask.new
10
16
 
11
17
  task default: :spec
@@ -26,8 +26,20 @@ module Imap::Backup
26
26
  def run
27
27
  Kernel.system("clear")
28
28
  Kernel.puts BANNER
29
- @client_id = highline.ask("client_id: ")
30
- @client_secret = highline.ask("client_secret: ")
29
+
30
+ keep = if token.valid?
31
+ highline.agree("Use existing client info?")
32
+ else
33
+ false
34
+ end
35
+
36
+ if keep
37
+ @client_id = token.client_id
38
+ @client_secret = token.client_secret
39
+ else
40
+ @client_id = highline.ask("client_id: ")
41
+ @client_secret = highline.ask("client_secret: ")
42
+ end
31
43
 
32
44
  Kernel.puts <<~MESSAGE
33
45
 
@@ -46,9 +58,9 @@ module Imap::Backup
46
58
 
47
59
  raise "Failed" if !@credentials
48
60
 
49
- token = JSON.parse(token_store.load(email))
50
- token["client_secret"] = client_secret
51
- token.to_json
61
+ new_token = JSON.parse(token_store.load(email))
62
+ new_token["client_secret"] = client_secret
63
+ new_token.to_json
52
64
  end
53
65
 
54
66
  private
@@ -57,6 +69,14 @@ module Imap::Backup
57
69
  account[:username]
58
70
  end
59
71
 
72
+ def password
73
+ account[:password]
74
+ end
75
+
76
+ def token
77
+ @token ||= Gmail::Authenticator::ImapBackupToken.new(password)
78
+ end
79
+
60
80
  def highline
61
81
  Configuration::Setup.highline
62
82
  end
@@ -2,8 +2,8 @@ module Imap; end
2
2
 
3
3
  module Imap::Backup
4
4
  MAJOR = 3
5
- MINOR = 2
6
- REVISION = 1
5
+ MINOR = 3
6
+ REVISION = 0
7
7
  PRE = nil
8
8
  VERSION = [MAJOR, MINOR, REVISION, PRE].compact.map(&:to_s).join(".")
9
9
  end
@@ -1,6 +1,9 @@
1
1
  describe Imap::Backup::Configuration::GmailOauth2 do
2
2
  include HighLineTestHelpers
3
3
 
4
+ CLIENT_ID = "my_client_id".freeze
5
+ CLIENT_SECRET = "my_client_secret".freeze
6
+
4
7
  subject { described_class.new(account) }
5
8
 
6
9
  let(:authorization_url) { "some long authorization_url" }
@@ -11,6 +14,7 @@ describe Imap::Backup::Configuration::GmailOauth2 do
11
14
  let(:input) { highline_streams[0] }
12
15
  let(:output) { highline_streams[1] }
13
16
  let(:account) { {} }
17
+ let(:user_input) { %W(my_client_id\n my_secret\n my_code\n) }
14
18
 
15
19
  let(:authorizer) do
16
20
  instance_double(
@@ -25,23 +29,31 @@ describe Imap::Backup::Configuration::GmailOauth2 do
25
29
  load: json_token
26
30
  )
27
31
  end
32
+ let(:token) do
33
+ instance_double(
34
+ Gmail::Authenticator::ImapBackupToken,
35
+ valid?: valid,
36
+ client_id: CLIENT_ID,
37
+ client_secret: CLIENT_SECRET
38
+ )
39
+ end
40
+ let(:valid) { false }
28
41
 
29
42
  before do
30
43
  allow(Google::Auth::UserAuthorizer).
31
44
  to receive(:new) { authorizer }
32
45
  allow(Google::Auth::Stores::InMemoryTokenStore).
33
46
  to receive(:new) { token_store }
47
+ allow(Gmail::Authenticator::ImapBackupToken).
48
+ to receive(:new) { token }
34
49
 
35
50
  allow(highline).to receive(:ask).and_call_original
51
+ allow(highline).to receive(:agree).and_call_original
36
52
 
37
53
  allow(Kernel).to receive(:system)
38
54
  allow(Kernel).to receive(:puts)
39
55
 
40
- allow(input).to receive(:gets).and_return(
41
- "my_client_id\n",
42
- "my_secret\n",
43
- "my_code\n"
44
- )
56
+ allow(input).to receive(:gets).and_return(*user_input)
45
57
  end
46
58
 
47
59
  describe "#run" do
@@ -80,5 +92,30 @@ describe Imap::Backup::Configuration::GmailOauth2 do
80
92
  it "includes the client_secret in the credentials" do
81
93
  expect(result).to match('"client_secret":"my_secret"')
82
94
  end
95
+
96
+ context "when the account already has client info" do
97
+ let(:valid) { true }
98
+ let(:user_input) { %W(yes\n) }
99
+
100
+ it "requests confirmation of client info" do
101
+ expect(highline).to have_received(:agree).with("Use existing client info?")
102
+ end
103
+
104
+ context "when yhe user says 'no'" do
105
+ let(:user_input) { %W(no\n) }
106
+
107
+ it "requests client_id" do
108
+ expect(highline).to have_received(:ask).with("client_id: ")
109
+ end
110
+
111
+ it "requests client_secret" do
112
+ expect(highline).to have_received(:ask).with("client_secret: ")
113
+ end
114
+
115
+ it "requests the success code" do
116
+ expect(highline).to have_received(:ask).with("success code: ")
117
+ end
118
+ end
119
+ end
83
120
  end
84
121
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: imap-backup
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.1
4
+ version: 3.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joe Yates
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-17 00:00:00.000000000 Z
11
+ date: 2021-02-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gmail_xoauth