File tree Expand file tree Collapse file tree 5 files changed +32
-25
lines changed
Filter options
Expand file tree Collapse file tree 5 files changed +32
-25
lines changed
Original file line number Diff line number Diff line change @@ -77,6 +77,7 @@ def name
77
77
# @return [void]
78
78
#
79
79
def download
80
+ validate_input
80
81
ui_action ( "#{ name } download" ) do
81
82
target_path . mkpath
82
83
download!
@@ -121,6 +122,14 @@ def checkout_options
121
122
raise 'Abstract method'
122
123
end
123
124
125
+ # Provides a before-download check for safety of the options in the
126
+ # concrete downloader.
127
+ #
128
+ # @return [void]
129
+ #
130
+ def validate_input
131
+ end
132
+
124
133
# Returns a User-Agent string that itentifies http network requests as
125
134
# originating from CocoaPods.
126
135
# Contains version numbers from the CocoaPods Gem and the cocoapods-downloader Gem.
Original file line number Diff line number Diff line change @@ -21,7 +21,6 @@ def checkout_options
21
21
end
22
22
23
23
def self . preprocess_options ( options )
24
- validate_input options
25
24
return options unless options [ :branch ]
26
25
27
26
command = [ 'ls-remote' ,
@@ -58,13 +57,7 @@ def self.commit_from_ls_remote(output, branch_name)
58
57
match [ 1 ] unless match . nil?
59
58
end
60
59
61
- def self . validate_input ( options )
62
- input = [ options [ :git ] , options [ :branch ] , options [ :commit ] , options [ :tag ] ] . map ( &:to_s )
63
- invalid = input . compact . any? { |value | value . start_with? ( '--' ) || value . include? ( ' --' ) }
64
- raise DownloaderError , "Provided unsafe input for git #{ options } ." if invalid
65
- end
66
-
67
- private_class_method :commit_from_ls_remote , :validate_input
60
+ private_class_method :commit_from_ls_remote
68
61
69
62
private
70
63
@@ -160,6 +153,12 @@ def checkout_commit
160
153
def target_git ( *args )
161
154
git! ( [ '-C' , target_path ] + args )
162
155
end
156
+
157
+ def validate_input
158
+ input = [ url , options [ :branch ] , options [ :commit ] , options [ :tag ] ] . map ( &:to_s )
159
+ invalid = input . compact . any? { |value | value . start_with? ( '--' ) || value . include? ( ' --' ) }
160
+ raise DownloaderError , "Provided unsafe input for git #{ options } ." if invalid
161
+ end
163
162
end
164
163
end
165
164
end
Original file line number Diff line number Diff line change @@ -18,19 +18,6 @@ def checkout_options
18
18
end
19
19
end
20
20
21
- def self . preprocess_options ( options )
22
- validate_input options
23
- options
24
- end
25
-
26
- def self . validate_input ( options )
27
- input = [ options [ :hg ] , options [ :revision ] , options [ :branch ] , options [ :tag ] ] . map ( &:to_s )
28
- invalid = input . compact . any? { |value | value . start_with? ( '--' ) || value . include? ( ' --' ) }
29
- raise DownloaderError , "Provided unsafe input for hg #{ options } ." if invalid
30
- end
31
-
32
- private_class_method :validate_input
33
-
34
21
private
35
22
36
23
executable :hg
@@ -62,6 +49,12 @@ def download_tag!
62
49
def download_branch!
63
50
hg! 'clone' , url , '--updaterev' , options [ :branch ] , @target_path
64
51
end
52
+
53
+ def validate_input
54
+ input = [ url , options [ :revision ] , options [ :branch ] , options [ :tag ] ] . map ( &:to_s )
55
+ invalid = input . compact . any? { |value | value . start_with? ( '--' ) || value . include? ( ' --' ) }
56
+ raise DownloaderError , "Provided unsafe input for hg #{ options } ." if invalid
57
+ end
65
58
end
66
59
end
67
60
end
Original file line number Diff line number Diff line change @@ -294,19 +294,19 @@ def ensure_only_one_ref(folder)
294
294
describe ':bad input' do
295
295
it 'bails when you provide a bad input' do
296
296
options = { :git => '--upload-pack=touch ./HELLO1;' , :branch => 'foo' }
297
- e = lambda { Downloader . preprocess_options ( options ) } . should . raise DownloaderError
297
+ e = lambda { Downloader . for_target ( tmp_folder , options ) . download } . should . raise DownloaderError
298
298
e . message . should . match /Provided unsafe input/
299
299
end
300
300
301
301
it 'bails when you provide a bad input after valid input' do
302
302
options = { :git => 'github.com --upload-pack=touch ./HELLO1;' , :branch => 'foo' }
303
- e = lambda { Downloader . preprocess_options ( options ) } . should . raise DownloaderError
303
+ e = lambda { Downloader . for_target ( tmp_folder , options ) . download } . should . raise DownloaderError
304
304
e . message . should . match /Provided unsafe input/
305
305
end
306
306
307
307
it 'bails with other fields' do
308
308
options = { :branch => '--upload-pack=touch ./HELLO1;' , :git => 'foo' }
309
- e = lambda { Downloader . preprocess_options ( options ) } . should . raise DownloaderError
309
+ e = lambda { Downloader . for_target ( tmp_folder , options ) . download } . should . raise DownloaderError
310
310
e . message . should . match /Provided unsafe input/
311
311
end
312
312
end
Original file line number Diff line number Diff line change @@ -110,7 +110,13 @@ module Downloader
110
110
describe ':bad input' do
111
111
it 'bails when you provide a bad input' do
112
112
options = { :hg => '--config=alias.clone=!touch ./HELLO2;' }
113
- e = lambda { Downloader . preprocess_options ( options ) } . should . raise DownloaderError
113
+ e = lambda { Downloader . for_target ( tmp_folder , options ) . download } . should . raise DownloaderError
114
+ e . message . should . match /Provided unsafe input/
115
+ end
116
+
117
+ it 'bails when you provide a bad input2' do
118
+ options = { :hg => 'foo/bar' , :revision => '--config=alias.clone=!touch ./HELLO3;' }
119
+ e = lambda { Downloader . for_target ( tmp_folder , options ) . download } . should . raise DownloaderError
114
120
e . message . should . match /Provided unsafe input/
115
121
end
116
122
end
You can’t perform that action at this time.
0 commit comments