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
8085adf8
Commit
8085adf8
authored
May 27, 2015
by
Michał Górny
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test: Add a test for in-memory SSH private key cred_cb
parent
2629fc87
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
68 additions
and
0 deletions
+68
-0
tests/online/clone.c
+68
-0
No files found.
tests/online/clone.c
View file @
8085adf8
...
...
@@ -501,6 +501,74 @@ void test_online_clone__ssh_cert(void)
cl_git_fail_with
(
GIT_EUSER
,
git_clone
(
&
g_repo
,
"ssh://localhost/foo"
,
"./foo"
,
&
g_options
));
}
static
char
*
read_key_file
(
const
char
*
path
)
{
FILE
*
f
;
char
*
buf
;
long
key_length
;
if
(
!
path
||
!*
path
)
return
NULL
;
cl_assert
((
f
=
fopen
(
path
,
"r"
))
!=
NULL
);
cl_assert
(
fseek
(
f
,
0
,
SEEK_END
)
!=
-
1
);
cl_assert
((
key_length
=
ftell
(
f
))
!=
-
1
);
cl_assert
(
fseek
(
f
,
0
,
SEEK_SET
)
!=
-
1
);
cl_assert
((
buf
=
malloc
(
key_length
))
!=
NULL
);
cl_assert
(
fread
(
buf
,
key_length
,
1
,
f
)
==
1
);
fclose
(
f
);
return
buf
;
}
static
int
ssh_memory_cred_cb
(
git_cred
**
cred
,
const
char
*
url
,
const
char
*
user_from_url
,
unsigned
int
allowed_types
,
void
*
payload
)
{
const
char
*
remote_user
=
cl_getenv
(
"GITTEST_REMOTE_USER"
);
const
char
*
pubkey_path
=
cl_getenv
(
"GITTEST_REMOTE_SSH_PUBKEY"
);
const
char
*
privkey_path
=
cl_getenv
(
"GITTEST_REMOTE_SSH_KEY"
);
const
char
*
passphrase
=
cl_getenv
(
"GITTEST_REMOTE_SSH_PASSPHRASE"
);
GIT_UNUSED
(
url
);
GIT_UNUSED
(
user_from_url
);
GIT_UNUSED
(
payload
);
if
(
allowed_types
&
GIT_CREDTYPE_USERNAME
)
return
git_cred_username_new
(
cred
,
remote_user
);
if
(
allowed_types
&
GIT_CREDTYPE_SSH_KEY
)
{
char
*
pubkey
=
read_key_file
(
pubkey_path
);
char
*
privkey
=
read_key_file
(
privkey_path
);
int
ret
=
git_cred_ssh_key_memory_new
(
cred
,
remote_user
,
pubkey
,
privkey
,
passphrase
);
if
(
privkey
)
free
(
privkey
);
if
(
pubkey
)
free
(
pubkey
);
return
ret
;
}
giterr_set
(
GITERR_NET
,
"unexpected cred type"
);
return
-
1
;
}
void
test_online_clone__ssh_memory_auth
(
void
)
{
const
char
*
remote_url
=
cl_getenv
(
"GITTEST_REMOTE_URL"
);
const
char
*
remote_user
=
cl_getenv
(
"GITTEST_REMOTE_USER"
);
const
char
*
privkey
=
cl_getenv
(
"GITTEST_REMOTE_SSH_KEY"
);
#ifndef GIT_SSH_MEMORY_CREDENTIALS
clar__skip
();
#endif
if
(
!
remote_url
||
!
remote_user
||
!
privkey
||
strncmp
(
remote_url
,
"ssh://"
,
5
)
!=
0
)
clar__skip
();
g_options
.
fetch_opts
.
callbacks
.
credentials
=
ssh_memory_cred_cb
;
cl_git_pass
(
git_clone
(
&
g_repo
,
remote_url
,
"./foo"
,
&
g_options
));
}
void
test_online_clone__url_with_no_path_returns_EINVALIDSPEC
(
void
)
{
cl_git_fail_with
(
git_clone
(
&
g_repo
,
"http://github.com"
,
"./foo"
,
&
g_options
),
...
...
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