gas 0.1.7 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
data/spec/gas/ssh_spec.rb DELETED
@@ -1,328 +0,0 @@
1
- require './spec/spec_helper'
2
-
3
- require './lib/gas'
4
-
5
- require 'rspec/mocks'
6
- require 'rspec/mocks/standalone'
7
-
8
- describe Gas::Ssh do
9
-
10
- before :all do
11
- move_the_testers_personal_ssh_key_out_of_way
12
- end
13
-
14
- after :all do
15
- restore_the_testers_ssh_key
16
- end
17
-
18
- before :each do
19
- @uid = "teddy"
20
- end
21
-
22
- describe "SSH key file handling..." do
23
-
24
- before :all do
25
- #Gas::Ssh.stub!(:delete).and_return(false)
26
- Gas::Ssh.stub!(:user_wants_to_delete_all_ssh_data?).and_return("l") # only delete's local keys
27
- end
28
-
29
- after :all do
30
- #Gas::Ssh.unstub!(:delete)
31
- Gas::Ssh.unstub!(:user_wants_to_delete_all_ssh_data?)
32
- end
33
-
34
- describe "Detecting when files are missing..." do
35
-
36
- before :all do
37
- File.stub!(:exists?).and_return(false) # make it so File.exists? always return true
38
- end
39
-
40
- after :all do
41
- File.unstub!(:exists?) # undoes the hook
42
- end
43
-
44
- it "should detect when an id_rsa isn't in the .gas directory" do
45
- Gas::Ssh.user_wants_to_use_key_already_in_gas?.should be_false
46
- end
47
-
48
- end
49
-
50
- describe "Detecting when files exist.@email..." do
51
- before :all do
52
- File.stub!(:exists?).and_return(true) # make it so File.exists? always return true
53
- end
54
-
55
- after :all do
56
- File.unstub!(:exists?) # undoes the hook
57
- end
58
-
59
- it 'should detect when an id_rsa is already in the .gas directory' do
60
- STDIN.stub!(:gets).and_return("y\n") # fix stdin to recieve a 'y' command...
61
- Gas::Ssh.user_wants_to_use_key_already_in_gas?.should be_true
62
- STDIN.unstub!(:gets)
63
- end
64
-
65
- end
66
-
67
- describe "File System Changes..." do
68
-
69
- before :all do
70
- @gas_dir = File.expand_path('~/.gas')
71
- @ssh_dir = File.expand_path('~/.ssh')
72
-
73
-
74
- @nickname = "thisaccountmaybedeletedmysteriously"
75
- @name = "tim T"
76
- @email = "tim@timmy.com"
77
-
78
- `rm ~/.gas/#{@nickname}_id_rsa`
79
- `rm ~/.gas/#{@nickname}_id_rsa.pub`
80
- Gas.delete(@nickname)
81
-
82
- # make sure that nickname isn't in use
83
- end
84
-
85
-
86
- it 'should create ssh keys in .gas && Gas.remove should be able to remove those files' do
87
- STDIN.stub!(:gets).and_return("y\n") # forces the dialogs to
88
- Gas::Ssh.stub!(:upload_public_key_to_github).and_return(false)
89
-
90
- lambda do
91
- Gas.add(@nickname,@name,@email)
92
- end.should change{`ls ~/.gas -1 | wc -l`.to_i}.by(2) #OMG THIS IS A FUN TEST!!!
93
-
94
- lambda do
95
- Gas.delete(@nickname)
96
- end.should change{`ls ~/.gas -1 | wc -l`.to_i}.by(-2)
97
-
98
- STDIN.unstub!(:gets)
99
- Gas::Ssh.unstub!(:upload_public_key_to_github)
100
- end
101
-
102
-
103
- describe 'For the ssh directory...' do
104
-
105
- before :each do
106
- # A user for creating
107
- @nickname = "thisaccountmaybedeletedmysteriously"
108
- @name = "tim T"
109
- @email = "tim@timmy.com"
110
-
111
- clean_out_ssh_directory
112
- clean_out_gas_directory(@nickname)
113
-
114
- # a user for deleting
115
- @nickname2 = "thisaccountmaybedeletedmysteriously2"
116
- @name2 = "tim T2"
117
- @email2 = "tim@timmy.com2"
118
- create_user_no_git(@nickname2, @name2, @email2)
119
- end
120
-
121
- after :each do
122
- Gas.delete(@nickname)
123
- delete_user_no_git(@nickname2)
124
- end
125
-
126
-
127
- it "if there's no key in .ssh" do
128
- # 1) Create a User
129
-
130
- # 2) Switch to that user
131
-
132
- # 3) The .ssh directory should now contain that file
133
- true.should be_true
134
-
135
- end
136
-
137
- it "if there's a key in ~/.ssh that isn't backed up in .gas" do
138
- # 1) Create a User
139
-
140
- # 2) Switch to that user
141
-
142
- # 3) The .ssh directory should now contain that file
143
-
144
- end
145
-
146
- it "If there's a key in ~/.ssh that's backed up in .gas"
147
-
148
- it "should delete the key in .ssh when the user is deleted" do
149
- # Gas.add(@nickname,@name,@email)
150
-
151
- end
152
-
153
- # bundle exec rspec spec/gas/ssh_spec.rb -e 'should be able to copy ssh keys in the ssh'
154
- it 'should be able to copy ssh keys in the ssh' do
155
- # put a key pair in the ssh directory
156
- mock_text = "this is a mock ssh file"
157
- File.open(SSH_DIRECTORY + "/id_rsa","w+").write(mock_text)
158
- File.open(SSH_DIRECTORY + "/id_rsa.pub","w+").write(mock_text)
159
-
160
- File.exists?(GAS_DIRECTORY + "/#{@nickname}_id_rsa").should be_false
161
- File.exists?(GAS_DIRECTORY + "/#{@nickname}_id_rsa.pub").should be_false
162
-
163
- Gas::Ssh.use_current_rsa_files_for_this_user(@nickname)
164
-
165
- File.exists?(GAS_DIRECTORY + "/#{@nickname}_id_rsa").should be_true
166
- File.exists?(GAS_DIRECTORY + "/#{@nickname}_id_rsa.pub").should be_true
167
-
168
- ssh_file = File.read(GAS_DIRECTORY + "/#{@nickname}_id_rsa")
169
- # ssh_file.should == mock_text # this part doesn't work... hmmm...
170
-
171
- File.delete(GAS_DIRECTORY + "/#{@nickname}_id_rsa")
172
- File.delete(GAS_DIRECTORY + "/#{@nickname}_id_rsa.pub")
173
- end
174
-
175
-
176
- it "should have a UTILITY for deleting rsa files of user" do
177
- lambda do
178
- Gas::Ssh.delete_associated_local_keys!(@nickname2)
179
- end.should change{`ls ~/.gas -1 | wc -l`.to_i}.by(-2)
180
- end
181
-
182
- end
183
-
184
- end
185
-
186
-
187
-
188
- end
189
-
190
- describe "Networking stuff..." do
191
-
192
- before :all do
193
- @name = 'Fredrik Wallgren'
194
- @email = 'fredrik.wallgren@gmail.com'
195
- @nickname = "thisaccountmaybedeletedmysteriously"
196
-
197
- # make sure sample key is deleted
198
- @username = "aTestGitAccount"
199
- @password = "plzdon'thackthetestaccount1"
200
-
201
- config = "[#{@nickname}]\n name = #{@name}\n email = #{@email}\n\n[user2]\n name = foo\n email = bar"
202
- @config = Gas::Config.new nil, config
203
- @user = @config.users[0]
204
-
205
- @credentials = {:username => @username, :password => @password}
206
-
207
- # Code to prepare the github environment for testing
208
- @sample_rsa = "ssh-rsa AAAAB3NzaC1yc2EAAAA55555AAABAQCpxktnw9eBaYkxLnvLq8ZeUI8d/d00MeV32na3GZ35qKtJ3Vmvzvb8anF1eZD8/+BtBgYer9/3E0KUi3YNYCeejkdUPj3/Z+aV7Ft0+IeKdzFSqfnfN9UsuS/zkeyia2bjgQJYqk2ZbkMuVIn79UI5ypJWGOXNfKyQ2adYJD7Pjgsxvx8qEXHlU+SszlGr7YFEFwT7rZtSXILylmcwCnZryy91cs50vGWxKzKrOV/2iMd8V4Qv7RbhKtQ7OCd19CaZ08H3xqcG1U2lqXIgxSN75bLL71AM0KfIvNOzvigBZnYyb/RKiUQUhA0FnnIYc/7hF9rOe/S1acRiOF6ihz1x"
209
-
210
-
211
- Gas::Ssh.remove_key!(@username, @password, @sample_rsa)
212
- Gas::Ssh.stub!(:get_username_and_password_and_authenticate).and_return(@credentials)
213
- end
214
-
215
- after :all do
216
- # make sure sample key is deleted
217
-
218
- Gas::Ssh.unstub!(:get_username_and_password_and_authenticate)
219
- end
220
-
221
- it "UTILITY: should be able to insert a new key into github and conversly remove that key" do
222
-
223
-
224
- lambda do
225
- Gas::Ssh.key_installation_routine!(@user, @sample_rsa)
226
- end.should change{Gas::Ssh.get_keys(@username, @password).length}.by(1)
227
-
228
- lambda do
229
- Gas::Ssh.remove_key!(@username, @password, @sample_rsa)
230
- end.should change{Gas::Ssh.get_keys(@username, @password).length}.by(-1)
231
- end
232
-
233
-
234
- # bundle exec rspec spec/gas/ssh_spec.rb SPEC_OPTS="-e \"should add ssh keys to github when user is created, and delete them when destroyed\""
235
- =begin
236
- rake spec SPEC=spec/gas/ssh_spec.rb \
237
- SPEC_OPTS="-e \"should add ssh keys to github when user is created, and delete them when destroyed\""
238
-
239
- bundle exec rspec spec/gas/ssh_spec.rb -e 'should add ssh keys to github when user is created, and delete them when destroyed'
240
-
241
- bundle exec rspec spec/gas/ssh_spec.rb -e 'UTILITY: should be able to insert a new key into github and conversly remove that key'
242
- =end
243
-
244
- it "should add ssh keys to github when user is created, and delete them when destroyed" do
245
-
246
- #move_the_testers_personal_ssh_key_out_of_way
247
-
248
- # yes, delete all
249
- Gas::Ssh.stub!(:user_wants_to_delete_all_ssh_data?).and_return("a") # all keys, local and github
250
- # create new user and use ssh handling
251
- Gas::Ssh.stub!(:user_wants_gas_to_handle_rsa_keys?).and_return(true)
252
- Gas::Ssh.stub!(:user_wants_to_use_key_already_in_ssh?).and_return(false)
253
- Gas::Ssh.stub!(:user_wants_to_install_key_to_github?).and_return(true)
254
-
255
-
256
- lambda do
257
- Gas.add(@nickname,@name,@email)
258
- end.should change{Gas::Ssh.get_keys(@username, @password).length}.by(1)
259
-
260
- lambda do
261
- Gas.delete(@nickname)
262
- end.should change{Gas::Ssh.get_keys(@username, @password).length}.by(-1)
263
-
264
-
265
- #restore_the_testers_ssh_key
266
-
267
- Gas::Ssh.unstub!(:user_wants_to_delete_all_ssh_data?)
268
- Gas::Ssh.unstub!(:user_wants_gas_to_handle_rsa_keys?)
269
- Gas::Ssh.unstub!(:user_wants_to_use_key_already_in_ssh?)
270
- Gas::Ssh.unstub!(:user_wants_to_install_key_to_github?)
271
- end
272
-
273
-
274
-
275
- it "Gas.Delete should be able to remove the id_rsa from .gas" do
276
- Gas::Ssh.stub!(:user_wants_to_delete_all_ssh_data?).and_return("a")
277
- Gas::Ssh.stub!(:user_wants_gas_to_handle_rsa_keys?).and_return(true)
278
- Gas::Ssh.stub!(:user_wants_to_use_key_already_in_ssh?).and_return(false)
279
- Gas::Ssh.stub!(:user_wants_to_install_key_to_github?).and_return(true)
280
-
281
- lambda do
282
- Gas.add(@nickname,@name,@email)
283
- end.should change{`ls ~/.gas -1 | wc -l`.to_i}.by(2)
284
-
285
- lambda do
286
- Gas.delete(@nickname)
287
- end.should change{`ls ~/.gas -1 | wc -l`.to_i}.by(-2)
288
-
289
-
290
- Gas::Ssh.unstub!(:user_wants_to_delete_all_ssh_data?)
291
- Gas::Ssh.unstub!(:user_wants_gas_to_handle_rsa_keys?)
292
- Gas::Ssh.unstub!(:user_wants_to_use_key_already_in_ssh?)
293
- Gas::Ssh.unstub!(:user_wants_to_install_key_to_github?)
294
- end
295
-
296
- # bundle exec rspec spec/gas/ssh_spec.rb -e 'Gas.ssh(nickname) should be able to add ssh support to a legacy user or an opt-out'
297
- it 'Gas.ssh(nickname) should be able to add ssh support to a legacy user or an opt-out' do
298
-
299
- Gas::Ssh.stub!(:user_wants_gas_to_handle_rsa_keys?).and_return(false)
300
- Gas.add(@nickname,@name,@email)
301
- Gas::Ssh.unstub!(:user_wants_gas_to_handle_rsa_keys?)
302
-
303
- Gas::Ssh.stub!(:user_wants_gas_to_handle_rsa_keys?).and_return(true)
304
- Gas::Ssh.stub!(:upload_public_key_to_github)
305
-
306
- lambda do
307
- Gas.ssh(@nickname)
308
- end.should change{`ls ~/.gas -1 | wc -l`.to_i}.by(2)
309
-
310
-
311
- Gas::Ssh.delete_associated_local_keys!(@nickname)
312
-
313
- Gas::Ssh.unstub!(:user_wants_gas_to_handle_rsa_keys?)
314
- Gas::Ssh.unstub!(:upload_public_key_to_github)
315
- end
316
-
317
-
318
-
319
- it "Should be able to tell if it's ever used this key under this ISP provider before and then warn the user"
320
-
321
- it 'Should have the ability to show if the author is associated with a specific github account NAME, stored in gas.accouts file'
322
-
323
- it 'Should have the ability to link up with non-github git-daemons'
324
- end
325
-
326
-
327
-
328
- end