@@ -107,7 +107,6 @@ test_expect_success 'store: if both xdg and home files exist, only store in home
107
107
test_must_be_empty "$HOME/.config/git/credentials"
108
108
'
109
109
110
-
111
110
test_expect_success ' erase: erase matching credentials from both xdg and home files' '
112
111
echo "https://home-user:[email protected] " >"$HOME/.git-credentials" &&
113
112
mkdir -p "$HOME/.config/git" &&
@@ -120,4 +119,94 @@ test_expect_success 'erase: erase matching credentials from both xdg and home fi
120
119
test_must_be_empty "$HOME/.config/git/credentials"
121
120
'
122
121
122
+ invalid_credential_test () {
123
+ test_expect_success " get: ignore credentials without $1 as invalid" '
124
+ echo "$2" >"$HOME/.git-credentials" &&
125
+ check fill store <<-\EOF
126
+ protocol=https
127
+ host=example.com
128
+ --
129
+ protocol=https
130
+ host=example.com
131
+ username=askpass-username
132
+ password=askpass-password
133
+ --
134
+ askpass: Username for ' \' ' https://example.com' \' ' :
135
+ askpass: Password for ' \' ' https://[email protected] ' \' ' :
136
+ --
137
+ EOF
138
+ '
139
+ }
140
+
141
+ invalid_credential_test
" scheme" ://user:
[email protected]
142
+ invalid_credential_test " valid host/path" https://user:pass@
143
+ invalid_credential_test
" username/password" https://
[email protected]
144
+
145
+ test_expect_success ' get: credentials with DOS line endings are invalid' '
146
+ printf "https://user:[email protected] \r\n" >"$HOME/.git-credentials" &&
147
+ check fill store <<-\EOF
148
+ protocol=https
149
+ host=example.com
150
+ --
151
+ protocol=https
152
+ host=example.com
153
+ username=askpass-username
154
+ password=askpass-password
155
+ --
156
+ askpass: Username for ' \' ' https://example.com' \' ' :
157
+ askpass: Password for ' \' ' https://[email protected] ' \' ' :
158
+ --
159
+ EOF
160
+ '
161
+
162
+ test_expect_success ' get: credentials with path and DOS line endings are valid' '
163
+ printf "https://user:[email protected] /repo.git\r\n" >"$HOME/.git-credentials" &&
164
+ check fill store <<-\EOF
165
+ url=https://example.com/repo.git
166
+ --
167
+ protocol=https
168
+ host=example.com
169
+ username=user
170
+ password=pass
171
+ --
172
+ EOF
173
+ '
174
+
175
+ test_expect_success ' get: credentials with DOS line endings are invalid if path is relevant' '
176
+ printf "https://user:[email protected] /repo.git\r\n" >"$HOME/.git-credentials" &&
177
+ test_config credential.useHttpPath true &&
178
+ check fill store <<-\EOF
179
+ url=https://example.com/repo.git
180
+ --
181
+ protocol=https
182
+ host=example.com
183
+ path=repo.git
184
+ username=askpass-username
185
+ password=askpass-password
186
+ --
187
+ askpass: Username for ' \' ' https://example.com/repo.git' \' ' :
188
+ askpass: Password for ' \' ' https://[email protected] /repo.git' \' ' :
189
+ --
190
+ EOF
191
+ '
192
+
193
+ test_expect_success ' get: store file can contain empty/bogus lines' '
194
+ echo "" >"$HOME/.git-credentials" &&
195
+ q_to_tab <<-\CREDENTIAL >>"$HOME/.git-credentials" &&
196
+ #comment
197
+ Q
198
+
199
+ CREDENTIAL
200
+ check fill store <<-\EOF
201
+ protocol=https
202
+ host=example.com
203
+ --
204
+ protocol=https
205
+ host=example.com
206
+ username=user
207
+ password=pass
208
+ --
209
+ EOF
210
+ '
211
+
123
212
test_done
0 commit comments