cocoapods-keys 1.2.1 → 1.3.0

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.
@@ -1,14 +1,13 @@
1
- require "keyring_liberator"
2
- require "name_whisperer"
1
+ require 'keyring_liberator'
2
+ require 'name_whisperer'
3
3
 
4
4
  module Pod
5
5
  class Command
6
6
  class Keys
7
-
8
7
  class Set < Keys
9
8
  include Config::Mixin
10
9
 
11
- self.summary = "A set values for keys."
10
+ self.summary = 'A set values for keys.'
12
11
 
13
12
  self.description = <<-DESC
14
13
  Save a environment key to be added to your project on the next pod install.
@@ -31,8 +30,8 @@ module Pod
31
30
  def validate!
32
31
  super
33
32
  verify_podfile_exists!
34
- help! "A key name is required to save." unless @key_name
35
- help! "A value is required for the key." unless @key_value
33
+ help! 'A key name is required to save.' unless @key_name
34
+ help! 'A value is required for the key.' unless @key_value
36
35
  end
37
36
 
38
37
  def run
@@ -40,16 +39,16 @@ module Pod
40
39
  # info "Saving into the keychain."
41
40
 
42
41
  keyring = current_keyring
43
- keyring.keys << @key_name.gsub("-", "_")
42
+ keyring.keys << @key_name.tr('-', '_')
44
43
  CocoaPodsKeys::KeyringLiberator.save_keyring keyring
45
44
 
46
45
  keyring.save @key_name, @key_value
47
46
 
48
- puts "Saved #{@key_name} to #{keyring.name}." unless config.silent?
47
+ UI.puts "Saved #{@key_name} to #{keyring.name}." unless config.silent?
49
48
  end
50
49
 
51
50
  def current_keyring
52
- current_dir = Dir.getwd
51
+ current_dir = Pathname.pwd
53
52
  keyring = CocoaPodsKeys::KeyringLiberator.get_keyring current_dir
54
53
 
55
54
  unless keyring
@@ -59,7 +58,6 @@ module Pod
59
58
 
60
59
  keyring
61
60
  end
62
-
63
61
  end
64
62
  end
65
63
  end
data/lib/preinstaller.rb CHANGED
@@ -8,9 +8,12 @@ module CocoaPodsKeys
8
8
  require 'key_master'
9
9
  require 'keyring_liberator'
10
10
  require 'pod/command/keys/set'
11
+ require 'cocoapods/user_interface'
12
+
13
+ ui = Pod::UserInterface
11
14
 
12
15
  options = @user_options || {}
13
- current_dir = Dir.getwd
16
+ current_dir = Pathname.pwd
14
17
  project = options.fetch('project') { CocoaPodsKeys::NameWhisperer.get_project_name }
15
18
  keyring = KeyringLiberator.get_keyring_named(project) || KeyringLiberator.get_keyring(current_dir)
16
19
 
@@ -18,31 +21,30 @@ module CocoaPodsKeys
18
21
 
19
22
  data = keyring.keychain_data
20
23
  has_shown_intro = false
21
- keys = options.fetch("keys", [])
24
+ keys = options.fetch('keys', [])
22
25
  keys.each do |key|
23
26
  unless data.keys.include? key
24
-
27
+
25
28
  unless has_shown_intro
26
- puts "\n CocoaPods-Keys has detected a keys mismatch for your setup."
29
+ ui.puts "\n CocoaPods-Keys has detected a keys mismatch for your setup."
27
30
  has_shown_intro = true
28
31
  end
29
-
30
- puts " What is the key for " + key.green
31
- answer = ""
32
+
33
+ ui.puts ' What is the key for ' + key.green
34
+ answer = ''
32
35
  loop do
33
- print " > "
34
- answer = STDIN.gets.chomp
36
+ ui.print ' > '
37
+ answer = ui.gets.strip
35
38
  break if answer.length > 0
36
39
  end
37
-
38
- puts ""
40
+
41
+ UI.puts
39
42
  args = CLAide::ARGV.new([key, answer, keyring.name])
40
43
  setter = Pod::Command::Keys::Set.new(args)
41
44
  setter.run
42
-
45
+
43
46
  end
44
47
  end
45
-
46
48
  end
47
49
  end
48
50
  end
@@ -22,27 +22,27 @@ describe 'CocoaPodsKeys functional tests' do
22
22
  PODFILE
23
23
  end
24
24
 
25
- system("pod keys set KeyWithData such-data --silent")
26
- system("pod keys set AnotherKeyWithData other-data --silent")
27
- system("pod keys set UnusedKey - --silent")
28
- system("pod install --silent --no-repo-update --no-integrate")
25
+ system('pod keys set KeyWithData such-data --silent')
26
+ system('pod keys set AnotherKeyWithData other-data --silent')
27
+ system('pod keys set UnusedKey - --silent')
28
+ system('pod install --silent --no-repo-update --no-integrate')
29
29
  end
30
30
  end
31
31
 
32
- it "does not directly encode the keys into the implementation file" do
32
+ it 'does not directly encode the keys into the implementation file' do
33
33
  source = File.read(File.join(@tmpdir, 'Pods/CocoaPodsKeys/TestProjectKeys.m'))
34
34
  expect(source).to_not include('such-data')
35
35
  expect(source).to_not include('other-data')
36
36
  end
37
37
 
38
- it "is able to retrieve the correct keys from the command-line" do
38
+ it 'is able to retrieve the correct keys from the command-line' do
39
39
  Dir.chdir(@tmpdir) do
40
40
  expect(`pod keys get KeyWithData`.strip).to eq('such-data')
41
41
  expect(`pod keys get AnotherKeyWithData`.strip).to eq('other-data')
42
42
  end
43
43
  end
44
44
 
45
- describe "with a built keys implementation" do
45
+ describe 'with a built keys implementation' do
46
46
  before :all do
47
47
  name = 'TestProjectKeys'
48
48
  dir = File.join(@tmpdir, 'Pods/CocoaPodsKeys')
@@ -52,15 +52,6 @@ describe 'CocoaPodsKeys functional tests' do
52
52
  @bundle = File.join(dir, "#{name}.bundle")
53
53
  end
54
54
 
55
- it "produces an implementation that is able to return the correct keys" do
56
- expect(fetch_key('keyWithData')).to eq('such-data')
57
- expect(fetch_key('anotherKeyWithData')).to eq('other-data')
58
- end
59
-
60
- xit "does not include keys that were not specified in the Podfile" do
61
- expect(lambda { fetch_key('unusedKey') }).to raise_error
62
- end
63
-
64
55
  private
65
56
 
66
57
  def fetch_key(key)
@@ -3,41 +3,9 @@ require 'key_master'
3
3
  require 'tmpdir'
4
4
 
5
5
  describe CocoaPodsKeys::KeyMaster do
6
- let(:empty_keys_interface) {
7
- File.read(fixture("Keys_empty.h"))
8
- }
9
-
10
- let(:empty_keys_implementation) {
11
- File.read(fixture("Keys_empty.m"))
12
- }
13
-
14
- it "should work with an empty keyring" do
15
- keyring = double("Keyring", keychain_data: [], code_name: "Fake")
16
- keymaster = described_class.new(keyring, Time.new(2015, 3, 11))
17
- expect(keymaster.name).to eq("FakeKeys")
18
- expect(keymaster.interface).to eq(empty_keys_interface)
19
- expect(keymaster.implementation).to eq(empty_keys_implementation)
20
- end
21
-
22
- it "should generate valid empty objc files", requires_clang: true do
23
- keyring = double("Keyring", keychain_data: [], code_name: "Fake")
24
- keymaster = described_class.new(keyring, Time.new(2015, 3, 11))
25
- expect(validate_syntax(keymaster)).to eq(true)
26
- end
27
-
28
- it "should escape backslashes" do
29
- keyring = double("Keyring", keychain_data: [], code_name: "Fake")
30
- keymaster = described_class.new(keyring, Time.new(2015, 3, 11))
31
- keymaster.instance_variable_set(:@data, '\4')
32
- expect(keymaster.generate_implementation).to include('"\\\4"')
33
- end
34
-
35
- it "should escape double-quotes" do
36
- keyring = double("Keyring", keychain_data: [], code_name: "Fake")
37
- keymaster = described_class.new(keyring, Time.new(2015, 3, 11))
38
- keymaster.instance_variable_set(:@data, '"')
39
- expect(keymaster.generate_implementation).to include('"\\""')
40
- end
6
+ # Previous tests operated under assumption that
7
+ # empty keychains were OK. See for more info:
8
+ # github.com/orta/cocoapods-keys/pull/68
41
9
 
42
10
  private
43
11
 
@@ -52,7 +20,7 @@ describe CocoaPodsKeys::KeyMaster do
52
20
  IO.write(m_file, keymaster.implementation)
53
21
  # attempt to validate syntax with clang
54
22
  Dir.chdir(dir)
55
- system(`xcrun --sdk macosx --find clang`.strip, "-fsyntax-only", m_file)
23
+ system(`xcrun --sdk macosx --find clang`.strip, '-fsyntax-only', m_file)
56
24
  end
57
25
  end
58
26
  end
@@ -6,25 +6,24 @@ require 'keyring'
6
6
  include CocoaPodsKeys
7
7
 
8
8
  describe KeyringLiberator do
9
- it "should get the keys directory" do
10
- expect(KeyringLiberator.keys_dir).to end_with("cocoapods/keys")
9
+ it 'should get the keys directory' do
10
+ expect(KeyringLiberator.keys_dir.to_s).to end_with('cocoapods/keys')
11
11
  end
12
12
 
13
- it "should append a sha + .yaml when getting the yaml path" do
14
- expect(KeyringLiberator.yaml_path_for_path("test")).to include("cocoapods/keys/")
15
- expect(KeyringLiberator.yaml_path_for_path("test")).to end_with("098f6bcd4621d373cade4e832627b4f6.yml")
13
+ it 'should append a sha + .yaml when getting the yaml path' do
14
+ expect(KeyringLiberator.yaml_path_for_path('test').to_s).to include('cocoapods/keys/')
15
+ expect(KeyringLiberator.yaml_path_for_path('test').to_s).to end_with('098f6bcd4621d373cade4e832627b4f6.yml')
16
16
  end
17
17
 
18
- it "should find by name" do
19
- keyring = Keyring.from_hash({ "name" => "test", "path" =>"testpath", "keys" => [] })
18
+ it 'should find by name' do
19
+ keyring = Keyring.from_hash('name' => 'test', 'path' => 'testpath', 'keys' => [])
20
20
  allow(KeyringLiberator).to receive(:get_all_keyrings).and_return([keyring])
21
- expect(KeyringLiberator.get_keyring_named("test")).to equal(keyring)
21
+ expect(KeyringLiberator.get_keyring_named('test')).to equal(keyring)
22
22
  end
23
23
 
24
- it "should be nil if nothing found find by name" do
25
- keyring = Keyring.from_hash({ "name" => "test", "path" =>"testpath", "keys" => [] })
24
+ it 'should be nil if nothing found find by name' do
25
+ keyring = Keyring.from_hash('name' => 'test', 'path' => 'testpath', 'keys' => [])
26
26
  allow(KeyringLiberator).to receive(:get_all_keyrings).and_return([keyring])
27
- expect(KeyringLiberator.get_keyring_named("not found")).to be_falsey
27
+ expect(KeyringLiberator.get_keyring_named('not found')).to be_falsey
28
28
  end
29
-
30
29
  end
data/spec/plugin_spec.rb CHANGED
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
  require 'cocoapods'
3
3
  require 'cocoapods-core'
4
4
  require 'plugin'
5
- #
5
+
6
6
  # include Pod
7
7
  #
8
8
  # describe Installer do
@@ -12,3 +12,195 @@ require 'plugin'
12
12
  # end
13
13
  #
14
14
  # end
15
+
16
+ RSpec.configure do |config|
17
+ config.mock_with :rspec do |mocks|
18
+ mocks.verify_partial_doubles = true
19
+ end
20
+ end
21
+
22
+ describe CocoaPodsKeys, '#plugin' do
23
+ before(:each) do
24
+ @config = Pod::Config.instance
25
+ @podfile = double('Podfile')
26
+ allow(@config).to receive(:podfile).and_return(@podfile)
27
+
28
+ @target_defs = double('TargetDefinition')
29
+ @target_a = double('TargetDefinition')
30
+ @target_b = double('TargetDefinition')
31
+
32
+ allow(@target_a).to receive(:label).and_return('Pods-TargetA')
33
+ allow(@target_b).to receive(:label).and_return('Pods-TargetB')
34
+ end
35
+
36
+ context 'with no targets defined in the Podfile' do
37
+ before(:each) do
38
+ allow(@podfile).to receive(:root_target_definitions).and_return([])
39
+ end
40
+
41
+ it 'adds Keys to the global Pod' do
42
+ expect(@podfile).to receive(:pod).with('Keys', anything)
43
+
44
+ CocoaPodsKeys.add_keys_to_pods(Pathname.new('Pods/CocoaPodsKeys/'), {})
45
+ end
46
+
47
+ %w(target targets).each do |target_tag|
48
+ context "with a non-existant target specified as a string in '#{target_tag}'" do
49
+ it 'fails to assign the key to the tag' do
50
+ expect(@podfile).not_to receive(:pod).with('Keys', anything)
51
+ expect(Pod::UI).to receive(:puts).with('Could not find a target named \'TargetA\' in your Podfile. Stopping keys'.red)
52
+
53
+ CocoaPodsKeys.add_keys_to_pods(Pathname.new('Pods/CocoaPodsKeys/'), target_tag => 'TargetA')
54
+ end
55
+ end
56
+
57
+ context "with a non-existant target specified as an array in '#{target_tag}'" do
58
+ it 'fails to assign the key to the tag' do
59
+ expect(@podfile).not_to receive(:pod).with('Keys', anything)
60
+ expect(Pod::UI).to receive(:puts).with('Could not find a target named \'TargetA\' in your Podfile. Stopping keys'.red)
61
+
62
+ CocoaPodsKeys.add_keys_to_pods(Pathname.new('Pods/CocoaPodsKeys/'), target_tag => ['TargetA'])
63
+ end
64
+ end
65
+ end
66
+ end
67
+
68
+ context 'with a single target defined in the Podfile' do
69
+ before(:each) do
70
+ @config = Pod::Config.instance
71
+ @podfile = double('Podfile')
72
+ allow(@config).to receive(:podfile).and_return(@podfile)
73
+
74
+ allow(@podfile).to receive(:root_target_definitions).and_return([@target_defs])
75
+ allow(@target_defs).to receive(:children).and_return([@target_a])
76
+ end
77
+
78
+ context 'with no targets specified' do
79
+ it 'adds Keys to the global Pod' do
80
+ expect(@podfile).to receive(:pod).with('Keys', anything)
81
+ expect(@target_a).not_to receive(:store_pod).with('Keys', anything)
82
+
83
+ CocoaPodsKeys.add_keys_to_pods(Pathname.new('Pods/CocoaPodsKeys/'), {})
84
+ end
85
+ end
86
+
87
+ %w(target targets).each do |target_tag|
88
+ context "with a string specified in '#{target_tag}'" do
89
+ it 'adds Keys to the target' do
90
+ expect(@podfile).not_to receive(:pod).with('Keys', anything)
91
+ expect(@target_a).to receive(:store_pod).with('Keys', anything)
92
+
93
+ CocoaPodsKeys.add_keys_to_pods(Pathname.new('Pods/CocoaPodsKeys/'), target_tag => 'TargetA')
94
+ end
95
+ end
96
+
97
+ context "with an array specified in '#{target_tag}'" do
98
+ it 'adds Keys to the target' do
99
+ expect(@podfile).not_to receive(:pod).with('Keys', anything)
100
+ expect(@target_a).to receive(:store_pod).with('Keys', anything)
101
+
102
+ CocoaPodsKeys.add_keys_to_pods(Pathname.new('Pods/CocoaPodsKeys/'), target_tag => ['TargetA'])
103
+ end
104
+ end
105
+
106
+ context "with a non-existant target specified as a string in '#{target_tag}'" do
107
+ it 'fails to assign the key to the tag' do
108
+ expect(@podfile).not_to receive(:pod).with('Keys', anything)
109
+ expect(Pod::UI).to receive(:puts).with('Could not find a target named \'TargetB\' in your Podfile. Stopping keys'.red)
110
+
111
+ CocoaPodsKeys.add_keys_to_pods(Pathname.new('Pods/CocoaPodsKeys/'), target_tag => 'TargetB')
112
+ end
113
+ end
114
+
115
+ context "with a non-existant target specified as an array in '#{target_tag}'" do
116
+ it 'fails to assign the key to the tag' do
117
+ expect(@podfile).not_to receive(:pod).with('Keys', anything)
118
+ expect(Pod::UI).to receive(:puts).with('Could not find a target named \'TargetB\' in your Podfile. Stopping keys'.red)
119
+
120
+ CocoaPodsKeys.add_keys_to_pods(Pathname.new('Pods/CocoaPodsKeys/'), target_tag => ['TargetB'])
121
+ end
122
+ end
123
+ end
124
+ end
125
+
126
+ context 'with two targets defined in the Podfile' do
127
+ before(:each) do
128
+ @config = Pod::Config.instance
129
+ @podfile = double('Podfile')
130
+ allow(@config).to receive(:podfile).and_return(@podfile)
131
+
132
+ allow(@podfile).to receive(:root_target_definitions).and_return([@target_defs])
133
+ allow(@target_defs).to receive(:children).and_return([@target_a, @target_b])
134
+ end
135
+
136
+ context 'with no targets specified' do
137
+ it 'adds Keys to the global Pod' do
138
+ expect(@podfile).to receive(:pod).with('Keys', anything)
139
+ expect(@target_a).not_to receive(:store_pod).with('Keys', anything)
140
+ expect(@target_b).not_to receive(:store_pod).with('Keys', anything)
141
+
142
+ CocoaPodsKeys.add_keys_to_pods(Pathname.new('Pods/CocoaPodsKeys/'), {})
143
+ end
144
+ end
145
+
146
+ %w(target targets).each do |target_tag|
147
+ context "with 'TargetA' specified as a string in '#{target_tag}'" do
148
+ it 'adds Keys to Target A' do
149
+ expect(@podfile).not_to receive(:pod).with('Keys', anything)
150
+ expect(@target_a).to receive(:store_pod).with('Keys', anything)
151
+ expect(@target_b).not_to receive(:store_pod).with('Keys', anything)
152
+
153
+ CocoaPodsKeys.add_keys_to_pods(Pathname.new('Pods/CocoaPodsKeys/'), target_tag => 'TargetA')
154
+ end
155
+ end
156
+
157
+ context "with 'TargetA' specified in an array in '#{target_tag}'" do
158
+ it 'adds Keys to Target A' do
159
+ expect(@podfile).not_to receive(:pod).with('Keys', anything)
160
+ expect(@target_a).to receive(:store_pod).with('Keys', anything)
161
+ expect(@target_b).not_to receive(:store_pod).with('Keys', anything)
162
+
163
+ CocoaPodsKeys.add_keys_to_pods(Pathname.new('Pods/CocoaPodsKeys/'), target_tag => ['TargetA'])
164
+ end
165
+ end
166
+
167
+ context "with 'TargetA' specified as a string in '#{target_tag}'" do
168
+ it 'adds Keys to Target B' do
169
+ expect(@podfile).not_to receive(:pod).with('Keys', anything)
170
+ expect(@target_a).not_to receive(:store_pod).with('Keys', anything)
171
+ expect(@target_b).to receive(:store_pod).with('Keys', anything)
172
+
173
+ CocoaPodsKeys.add_keys_to_pods(Pathname.new('Pods/CocoaPodsKeys/'), target_tag => 'TargetB')
174
+ end
175
+ end
176
+
177
+ context "with 'TargetB' specified in an array in '#{target_tag}'" do
178
+ it 'adds Keys to Target B' do
179
+ expect(@podfile).not_to receive(:pod).with('Keys', anything)
180
+ expect(@target_a).not_to receive(:store_pod).with('Keys', anything)
181
+ expect(@target_b).to receive(:store_pod).with('Keys', anything)
182
+
183
+ CocoaPodsKeys.add_keys_to_pods(Pathname.new('Pods/CocoaPodsKeys/'), target_tag => ['TargetB'])
184
+ end
185
+ end
186
+
187
+ context "with a non-existant target specified as a string in '#{target_tag}'" do
188
+ it 'fails to assign the key to the tag' do
189
+ expect(@podfile).not_to receive(:pod).with('Keys', anything)
190
+ expect(Pod::UI).to receive(:puts).with('Could not find a target named \'TargetC\' in your Podfile. Stopping keys'.red)
191
+
192
+ CocoaPodsKeys.add_keys_to_pods(Pathname.new('Pods/CocoaPodsKeys/'), target_tag => 'TargetC')
193
+ end
194
+ end
195
+
196
+ context "with a non-existant target specified as an array in '#{target_tag}'" do
197
+ it 'fails to assign the key to the tag' do
198
+ expect(@podfile).not_to receive(:pod).with('Keys', anything)
199
+ expect(Pod::UI).to receive(:puts).with('Could not find a target named \'TargetC\' in your Podfile. Stopping keys'.red)
200
+
201
+ CocoaPodsKeys.add_keys_to_pods(Pathname.new('Pods/CocoaPodsKeys/'), target_tag => ['TargetC'])
202
+ end
203
+ end
204
+ end
205
+ end
206
+ end