Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
3245896b
Commit
3245896b
authored
Sep 10, 2015
by
Matt Burke
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a test for custom header validation
Also, *some* custom headers actually are valid.
parent
66d90e70
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
6 deletions
+39
-6
src/transports/smart.c
+12
-6
tests/online/clone.c
+27
-0
No files found.
src/transports/smart.c
View file @
3245896b
...
...
@@ -66,6 +66,10 @@ static int git_smart__set_callbacks(
return
0
;
}
#define forbid_custom_header(disallowed_name) \
if (strncmp(disallowed_name, custom_header, name_len) == 0) \
return false
bool
is_valid_custom_header
(
const
char
*
custom_header
)
{
const
char
*
c
;
...
...
@@ -91,12 +95,14 @@ bool is_valid_custom_header(const char *custom_header)
return
false
;
// Disallow headers that we set
return
git__strncmp
(
"User-Agent"
,
custom_header
,
name_len
)
==
0
&&
git__strncmp
(
"Host"
,
custom_header
,
name_len
)
==
0
&&
git__strncmp
(
"Accept"
,
custom_header
,
name_len
)
==
0
&&
git__strncmp
(
"Content-Type"
,
custom_header
,
name_len
)
==
0
&&
git__strncmp
(
"Transfer-Encoding"
,
custom_header
,
name_len
)
==
0
&&
git__strncmp
(
"Content-Length"
,
custom_header
,
name_len
)
==
0
;
forbid_custom_header
(
"User-Agent"
);
forbid_custom_header
(
"Host"
);
forbid_custom_header
(
"Accept"
);
forbid_custom_header
(
"Content-Type"
);
forbid_custom_header
(
"Transfer-Encoding"
);
forbid_custom_header
(
"Content-Length"
);
return
true
;
}
const
char
*
find_invalid_custom_header
(
const
git_strarray
*
custom_headers
)
...
...
tests/online/clone.c
View file @
3245896b
...
...
@@ -213,6 +213,33 @@ void test_online_clone__custom_remote_callbacks(void)
cl_assert
(
callcount
>
0
);
}
void
test_online_clone__custom_headers
(
void
)
{
char
*
empty_header
=
""
;
char
*
unnamed_header
=
"this is a header about nothing"
;
char
*
newlines
=
"X-Custom: almost OK
\n
"
;
char
*
conflict
=
"Accept: defined-by-git"
;
char
*
ok
=
"X-Custom: this should be ok"
;
g_options
.
fetch_opts
.
custom_headers
.
count
=
1
;
g_options
.
fetch_opts
.
custom_headers
.
strings
=
&
empty_header
;
cl_git_fail
(
git_clone
(
&
g_repo
,
LIVE_REPO_URL
,
"./foo"
,
&
g_options
));
g_options
.
fetch_opts
.
custom_headers
.
strings
=
&
unnamed_header
;
cl_git_fail
(
git_clone
(
&
g_repo
,
LIVE_REPO_URL
,
"./foo"
,
&
g_options
));
g_options
.
fetch_opts
.
custom_headers
.
strings
=
&
newlines
;
cl_git_fail
(
git_clone
(
&
g_repo
,
LIVE_REPO_URL
,
"./foo"
,
&
g_options
));
g_options
.
fetch_opts
.
custom_headers
.
strings
=
&
conflict
;
cl_git_fail
(
git_clone
(
&
g_repo
,
LIVE_REPO_URL
,
"./foo"
,
&
g_options
));
/* Finally, we got it right! */
g_options
.
fetch_opts
.
custom_headers
.
strings
=
&
ok
;
cl_git_pass
(
git_clone
(
&
g_repo
,
LIVE_REPO_URL
,
"./foo"
,
&
g_options
));
}
static
int
cred_failure_cb
(
git_cred
**
cred
,
const
char
*
url
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment