@@ -23,29 +23,29 @@ def test_add_remote
23
23
assert ( local . remotes . map { |b | b . name } . include? ( 'testremote2' ) )
24
24
25
25
local . add_remote ( 'testremote3' , remote , :track => 'master' )
26
-
27
- assert ( local . branches . map { |b | b . full } . include? ( 'master' ) ) #We actually a new branch ('test_track') on the remote and track that one intead.
26
+
27
+ assert ( local . branches . map { |b | b . full } . include? ( 'master' ) ) #We actually a new branch ('test_track') on the remote and track that one intead.
28
28
assert ( local . remotes . map { |b | b . name } . include? ( 'testremote3' ) )
29
- end
29
+ end
30
30
end
31
31
32
32
def test_remove_remote_remove
33
33
in_temp_dir do |path |
34
34
local = Git . clone ( @wbare , 'local' )
35
35
remote = Git . clone ( @wbare , 'remote' )
36
-
36
+
37
37
local . add_remote ( 'testremote' , remote )
38
38
local . remove_remote ( 'testremote' )
39
-
39
+
40
40
assert ( !local . remotes . map { |b | b . name } . include? ( 'testremote' ) )
41
41
42
42
local . add_remote ( 'testremote' , remote )
43
43
local . remote ( 'testremote' ) . remove
44
-
44
+
45
45
assert ( !local . remotes . map { |b | b . name } . include? ( 'testremote' ) )
46
46
end
47
47
end
48
-
48
+
49
49
def test_set_remote_url
50
50
in_temp_dir do |path |
51
51
local = Git . clone ( @wbare , 'local' )
@@ -65,33 +65,33 @@ def test_remote_fun
65
65
in_temp_dir do |path |
66
66
loc = Git . clone ( @wbare , 'local' )
67
67
rem = Git . clone ( @wbare , 'remote' )
68
-
68
+
69
69
r = loc . add_remote ( 'testrem' , rem )
70
70
71
71
Dir . chdir ( 'remote' ) do
72
72
new_file ( 'test-file1' , 'blahblahblah1' )
73
73
rem . add
74
74
rem . commit ( 'master commit' )
75
-
75
+
76
76
rem . branch ( 'testbranch' ) . in_branch ( 'tb commit' ) do
77
77
new_file ( 'test-file3' , 'blahblahblah3' )
78
78
rem . add
79
- true
79
+ true
80
80
end
81
81
end
82
82
assert ( !loc . status [ 'test-file1' ] )
83
83
assert ( !loc . status [ 'test-file3' ] )
84
-
84
+
85
85
r . fetch
86
- r . merge
86
+ r . merge
87
87
assert ( loc . status [ 'test-file1' ] )
88
-
88
+
89
89
loc . merge ( loc . remote ( 'testrem' ) . branch ( 'testbranch' ) )
90
- assert ( loc . status [ 'test-file3' ] )
91
-
90
+ assert ( loc . status [ 'test-file3' ] )
91
+
92
92
#puts loc.remotes.map { |r| r.to_s }.inspect
93
-
94
- #r.remove
93
+
94
+ #r.remove
95
95
#puts loc.remotes.inspect
96
96
end
97
97
end
@@ -123,18 +123,37 @@ def test_fetch
123
123
end
124
124
end
125
125
126
+ def test_fetch_command_injection
127
+ test_file = 'VULNERABILITY_EXISTS'
128
+ vulnerability_exists = false
129
+ in_temp_dir do |_path |
130
+ git = Git . init ( 'test_project' )
131
+ origin = "--upload-pack=touch #{ test_file } ;"
132
+ begin
133
+ git . fetch ( origin , { ref : 'some/ref/head' } )
134
+ rescue Git ::GitExecuteError
135
+ # This is expected
136
+ else
137
+ raise 'Expected Git::GitExecuteError to be raised'
138
+ end
139
+
140
+ vulnerability_exists = File . exist? ( test_file )
141
+ end
142
+ assert ( !vulnerability_exists )
143
+ end
144
+
126
145
def test_fetch_ref_adds_ref_option
127
146
in_temp_dir do |path |
128
147
loc = Git . clone ( @wbare , 'local' )
129
148
rem = Git . clone ( @wbare , 'remote' , :config => 'receive.denyCurrentBranch=ignore' )
130
149
loc . add_remote ( 'testrem' , rem )
131
-
150
+
132
151
loc . chdir do
133
152
new_file ( 'test-file1' , 'gonnaCommitYou' )
134
153
loc . add
135
154
loc . commit ( 'master commit 1' )
136
155
first_commit_sha = loc . log . first . sha
137
-
156
+
138
157
new_file ( 'test-file2' , 'gonnaCommitYouToo' )
139
158
loc . add
140
159
loc . commit ( 'master commit 2' )
@@ -146,46 +165,46 @@ def test_fetch_ref_adds_ref_option
146
165
147
166
# Make sure fetch message only has the second commit when we fetch the second commit
148
167
assert ( loc . fetch ( 'origin' , { :ref => second_commit_sha } ) . include? ( second_commit_sha ) )
149
- assert ( !loc . fetch ( 'origin' , { :ref => second_commit_sha } ) . include? ( first_commit_sha ) )
150
- end
168
+ assert ( !loc . fetch ( 'origin' , { :ref => second_commit_sha } ) . include? ( first_commit_sha ) )
169
+ end
151
170
end
152
171
end
153
-
172
+
154
173
def test_push
155
174
in_temp_dir do |path |
156
175
loc = Git . clone ( @wbare , 'local' )
157
176
rem = Git . clone ( @wbare , 'remote' , :config => 'receive.denyCurrentBranch=ignore' )
158
-
177
+
159
178
loc . add_remote ( 'testrem' , rem )
160
179
161
180
loc . chdir do
162
181
new_file ( 'test-file1' , 'blahblahblah1' )
163
182
loc . add
164
183
loc . commit ( 'master commit' )
165
184
loc . add_tag ( 'test-tag' )
166
-
185
+
167
186
loc . branch ( 'testbranch' ) . in_branch ( 'tb commit' ) do
168
187
new_file ( 'test-file3' , 'blahblahblah3' )
169
188
loc . add
170
- true
189
+ true
171
190
end
172
191
end
173
192
assert ( !rem . status [ 'test-file1' ] )
174
193
assert ( !rem . status [ 'test-file3' ] )
175
-
194
+
176
195
loc . push ( 'testrem' )
177
196
178
- assert ( rem . status [ 'test-file1' ] )
179
- assert ( !rem . status [ 'test-file3' ] )
197
+ assert ( rem . status [ 'test-file1' ] )
198
+ assert ( !rem . status [ 'test-file3' ] )
180
199
assert_raise Git ::GitTagNameDoesNotExist do
181
200
rem . tag ( 'test-tag' )
182
201
end
183
-
202
+
184
203
loc . push ( 'testrem' , 'testbranch' , true )
185
204
186
205
rem . checkout ( 'testbranch' )
187
- assert ( rem . status [ 'test-file1' ] )
188
- assert ( rem . status [ 'test-file3' ] )
206
+ assert ( rem . status [ 'test-file1' ] )
207
+ assert ( rem . status [ 'test-file3' ] )
189
208
assert ( rem . tag ( 'test-tag' ) )
190
209
end
191
210
end
0 commit comments