File tree Expand file tree Collapse file tree 2 files changed +23
-4
lines changed Expand file tree Collapse file tree 2 files changed +23
-4
lines changed Original file line number Diff line number Diff line change @@ -94,9 +94,9 @@ def clear
9494 end
9595
9696 def check_permissions
97- open_auth_file ( 'r+' ) { return true }
98- rescue
99- puts "error: could not open #{ auth_file } "
97+ open_auth_file ( 'r+' ) { true }
98+ rescue => ex
99+ puts "error: could not open #{ auth_file } : #{ ex } "
100100 if File . exist? ( auth_file )
101101 system ( 'ls' , '-l' , auth_file )
102102 else
Original file line number Diff line number Diff line change 1515 it { gitlab_keys . instance_variable_get ( :@key_id ) . should == 'key-741' }
1616 end
1717
18-
1918 describe :add_key do
2019 let ( :gitlab_keys ) { build_gitlab_keys ( 'add-key' , 'key-741' , 'ssh-rsa AAAAB3NzaDAxx2E' ) }
2120
145144 end
146145 end
147146
147+ describe :check_permissions do
148+ let ( :gitlab_keys ) { build_gitlab_keys ( 'check-permissions' ) }
149+
150+ it 'returns true when the file can be opened' do
151+ create_authorized_keys_fixture
152+ expect ( gitlab_keys . exec ) . to eq ( true )
153+ end
154+
155+ it 'returns false if opening raises an exception' do
156+ gitlab_keys . should_receive ( :open_auth_file ) . and_raise ( "imaginary error" )
157+ expect ( gitlab_keys . exec ) . to eq ( false )
158+ end
159+ end
160+
148161 describe :exec do
149162 it 'add-key arg should execute add_key method' do
150163 gitlab_keys = build_gitlab_keys ( 'add-key' )
170183 gitlab_keys . exec
171184 end
172185
186+ it 'check-permissions arg should execute check_permissions method' do
187+ gitlab_keys = build_gitlab_keys ( 'check-permissions' )
188+ gitlab_keys . should_receive ( :check_permissions )
189+ gitlab_keys . exec
190+ end
191+
173192 it 'should puts message if unknown command arg' do
174193 gitlab_keys = build_gitlab_keys ( 'change-key' )
175194 gitlab_keys . should_receive ( :puts ) . with ( 'not allowed' )
You can’t perform that action at this time.
0 commit comments