FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python-gitlab/tests/functional/api/test_keys.py at main · python-gitlab/python-gitlab · GitHub
python-gitlab
python-gitlab
Repository navigation
Code
Issues
16
(16)
Pull requests
15
(15)
Discussions
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
python-gitlab
/
tests
/
functional
/
api
/
test_keys.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
51 lines (38 loc) · 1.46 KB
Breadcrumbs
python-gitlab
/
tests
/
functional
/
api
/
test_keys.py
Copy path
File metadata and controls
51 lines (38 loc) · 1.46 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
"""
GitLab API:
https://docs.gitlab.com/ce/api/keys.html
"""
import
base64
import
hashlib
def
key_fingerprint
(
key
:
str
)
->
str
:
key_part
=
key
.
split
()[
1
]
decoded
=
base64
.
b64decode
(
key_part
.
encode
(
"ascii"
))
digest
=
hashlib
.
sha256
(
decoded
).
digest
()
return
f"SHA256:
{
base64
.
b64encode
(
digest
).
rstrip
(
b'='
).
decode
(
'utf-8'
)
}
"
def
test_keys_ssh
(
gl
,
user
,
SSH_KEY
):
key
=
user
.
keys
.
create
({
"title"
:
"foo@bar"
,
"key"
:
SSH_KEY
})
# Get key by ID (admin only).
key_by_id
=
gl
.
keys
.
get
(
key
.
id
)
assert
key_by_id
.
title
==
key
.
title
assert
key_by_id
.
key
==
key
.
key
fingerprint
=
key_fingerprint
(
SSH_KEY
)
# Get key by fingerprint (admin only).
key_by_fingerprint
=
gl
.
keys
.
get
(
fingerprint
=
fingerprint
)
assert
key_by_fingerprint
.
title
==
key
.
title
assert
key_by_fingerprint
.
key
==
key
.
key
key
.
delete
()
def
test_keys_deploy
(
gl
,
project
,
DEPLOY_KEY
):
key
=
project
.
keys
.
create
({
"title"
:
"foo@bar"
,
"key"
:
DEPLOY_KEY
})
fingerprint
=
key_fingerprint
(
DEPLOY_KEY
)
key_by_fingerprint
=
gl
.
keys
.
get
(
fingerprint
=
fingerprint
)
assert
key_by_fingerprint
.
title
==
key
.
title
assert
key_by_fingerprint
.
key
==
key
.
key
if
not
any
(
key_project
.
get
(
"project_id"
)
==
project
.
id
for
key_project
in
key_by_fingerprint
.
deploy_keys_projects
):
raise
AssertionError
(
f"Project
{
project
}
not found in 'deploy_keys_projects' "
f"
{
key_by_fingerprint
.
pformat
()
}
"
)
key
.
delete
()
Back
|
FazBrowse Home
|
New Git URL