Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
佳 邓
Gitlab4j Api
Commits
b47733e2
Commit
b47733e2
authored
Jul 15, 2020
by
Greg Messner
Browse files
Fixed tests related to SSH keys
parent
c20d0d36
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/test/java/org/gitlab4j/api/TestUserApi.java
View file @
b47733e2
...
...
@@ -57,12 +57,12 @@ public class TestUserApi extends AbstractIntegrationTest {
private
static
final
String
TEST_SUDO_AS_USERNAME
=
HelperUtils
.
getProperty
(
SUDO_AS_USERNAME_KEY
);
private
static
final
String
TEST_IMPERSONATION_TOKEN_NAME
=
"token1"
;
private
static
final
String
TEST_SSH_KEY
=
"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC
vbkmGRaANy2nmLrfYa9LkjMqjs9twYZXQKUPK18j
"
+
"BWmNgnAm818IikxjfFit3Gqnnh9zdNzlzUYs2osmfdHwRLeFY3hKVR6WckGYVroQuV5ArUA4+oME+IIQ2soCv/
"
+
"vNWfEmp2N1mpBTwi2mIYKurCKv6UpIpGK9D+ezNk5H0waVTK8EvZ/ey69Nu7C7RsbTYeyi5WY/jaUG5JbsEeKY
"
+
"IW/2DIlUts7gcB2hzXtt7r7+6DLx82Vb+S2jPZu2JQaB4zfgS7LQgzHUy1aAAgUUpuAbvWzuGHKO0p551Ru4qi"
+
"tyXN2+OUVXcYAsuIIdGGB0wLvTDgiOOSZWnSE+sg6XX user@example.com"
;
private
static
final
String
TEST_SSH_KEY
=
"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC
3rWzl/oPAD+Em2iGTmR81HcYZsopvnKp7jelI4XS91fT1NjCRrGsxf5Mw/
"
+
"KnmtBjhk+kQjkhIrnsBDcs6DZWtNcHJtyWJZrYsfxMTqWCaQv+OTRwVboqS2pmPcbK3gizUd5GCLFTKbg4OMpdywTwi6NAPwQ
"
+
"rtn3xwiVnGGCfBSyRFppcYP81otALctrlAW57V5+bQwFIJteJ+NWe1UmPxrqQ0N/a+dEEoJHzwX8RtVSkULafrRw8avn6Zp2x
"
+
"1OlD2aIEMQWvepNTRW6UDMSmWFc61ycy1pF5sCT5rij+b/fN4qCEvQs6R7GmCzaaZzbWuAqaxLRdITm/WUxdG6rjh"
;
private
static
final
String
TEST_USER_EMAIL
=
"test-user-email123@gitlab4j.org"
;
private
static
final
String
TEST_EXTERNAL_USERNAME
=
HelperUtils
.
getProperty
(
EXTERNAL_USERNAME_KEY
);
...
...
@@ -114,7 +114,7 @@ public class TestUserApi extends AbstractIntegrationTest {
List
<
SshKey
>
sshKeys
=
gitLabApi
.
getUserApi
().
getSshKeys
();
if
(
sshKeys
!=
null
)
{
for
(
SshKey
key
:
sshKeys
)
{
if
(
TEST_SSH_KEY
.
equals
(
key
.
getKey
()
))
{
if
(
key
.
getKey
().
startsWith
(
TEST_SSH_KEY
))
{
gitLabApi
.
getUserApi
().
deleteSshKey
(
key
.
getId
());
}
}
...
...
@@ -367,14 +367,19 @@ public class TestUserApi extends AbstractIntegrationTest {
assumeTrue
(
TEST_SSH_KEY
!=
null
);
SshKey
sshKey
=
gitLabApi
.
getUserApi
().
addSshKey
(
"Test-Key"
,
TEST_SSH_KEY
);
assertNotNull
(
sshKey
);
assert
Equals
(
TEST_SSH_KEY
,
sshKey
.
getKey
());
assert
True
(
TEST_SSH_KEY
,
sshKey
.
getKey
()
.
startsWith
(
TEST_SSH_KEY
)
);
gitLabApi
.
getUserApi
().
deleteSshKey
(
sshKey
.
getId
());
User
user
=
gitLabApi
.
getUserApi
().
getCurrentUser
();
sshKey
=
gitLabApi
.
getUserApi
().
addSshKey
(
user
.
getId
(),
"Test-Key1"
,
TEST_SSH_KEY
);
assertNotNull
(
sshKey
);
assert
Equals
(
TEST_SSH_KEY
,
sshKey
.
getKey
());
assert
True
(
TEST_SSH_KEY
,
sshKey
.
getKey
()
.
startsWith
(
TEST_SSH_KEY
)
);
assertEquals
(
user
.
getId
(),
sshKey
.
getUserId
());
Optional
<
SshKey
>
optional
=
gitLabApi
.
getUserApi
().
getOptionalSshKey
(
sshKey
.
getId
());
assertNotNull
(
optional
.
isPresent
());
assertTrue
(
TEST_SSH_KEY
,
sshKey
.
getKey
().
startsWith
(
TEST_SSH_KEY
));
gitLabApi
.
getUserApi
().
deleteSshKey
(
sshKey
.
getId
());
}
...
...
@@ -383,7 +388,7 @@ public class TestUserApi extends AbstractIntegrationTest {
assumeTrue
(
TEST_SSH_KEY
!=
null
);
User
user
=
gitLabApi
.
getUserApi
().
getCurrentUser
();
SshKey
sshKey
=
gitLabApi
.
getUserApi
().
addSshKey
(
user
.
getId
(),
"Test-Key
1
"
,
TEST_SSH_KEY
);
SshKey
sshKey
=
gitLabApi
.
getUserApi
().
addSshKey
(
user
.
getId
(),
"Test-Key
2
"
,
TEST_SSH_KEY
);
assertNotNull
(
sshKey
);
Optional
<
SshKey
>
optional
=
gitLabApi
.
getUserApi
().
getOptionalSshKey
(
sshKey
.
getId
());
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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