Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
Learn keyring
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Oleksiy Kashuba
Learn keyring
Commits
ceed44de
Commit
ceed44de
authored
3 months ago
by
Alex Kashuba
Browse files
Options
Downloads
Patches
Plain Diff
Tested keyring set/get
parent
b49e1d02
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main.py
+30
-2
30 additions, 2 deletions
src/main.py
tests/test_keyring.py
+52
-7
52 additions, 7 deletions
tests/test_keyring.py
with
82 additions
and
9 deletions
src/main.py
+
30
−
2
View file @
ceed44de
from
urllib.parse
import
urlparse
import
getpass
import
sys
def
parse
url
(
url
):
def
parse
_credentials
(
url
):
result
=
urlparse
(
url
)
return
result
.
netloc
if
result
.
username
is
None
:
username
=
getpass
.
getuser
()
else
:
username
=
result
.
username
if
result
.
port
is
None
:
hostname
=
result
.
hostname
else
:
hostname
=
result
.
hostname
+
'
:
'
+
str
(
result
.
port
)
return
'
MDDB (
'
+
hostname
+
'
)
'
,
username
def
get_user_full_name
():
if
sys
.
platform
==
'
win32
'
:
import
ctypes
GetUserNameEx
=
ctypes
.
windll
.
secur32
.
GetUserNameExW
NameDisplay
=
3
size
=
ctypes
.
pointer
(
ctypes
.
c_ulong
(
0
))
GetUserNameEx
(
NameDisplay
,
None
,
size
)
nameBuffer
=
ctypes
.
create_unicode_buffer
(
size
.
contents
.
value
)
GetUserNameEx
(
NameDisplay
,
nameBuffer
,
size
)
return
nameBuffer
.
value
else
:
import
pwd
,
os
pwd_data
=
pwd
.
getpwuid
(
os
.
getuid
())
return
pwd_data
.
pw_gecos
# Press the green button in the gutter to run the script.
...
...
This diff is collapsed.
Click to expand it.
tests/test_keyring.py
+
52
−
7
View file @
ceed44de
from
pytest
import
fixture
from
main
import
parseurl
import
keyring
from
pytest
import
fixture
,
mark
from
main
import
parse_credentials
import
sys
,
os
@fixture
def
url
():
return
"
https://kashuba@metadata.institut2c.physik.rwth-aachen.de:8123/api/
"
def
ex_whoami
(
ex_user
):
if
ex_user
is
None
:
if
sys
.
platform
==
'
darwin
'
:
return
os
.
getenv
(
'
USER
'
)
else
:
return
os
.
getlogin
()
else
:
return
ex_user
def
test_urlparse
(
url
):
print
()
print
(
parseurl
(
url
))
\ No newline at end of file
@fixture
def
ex_service
(
ex_host
):
return
'
MDDB (
'
+
ex_host
+
'
)
'
@mark.parametrize
(
"
uri,ex_user,ex_host
"
,
[(
"
https://kashuba@metadata.institut2c.physik.rwth-aachen.de:8123/api/
"
,
'
kashuba
'
,
'
metadata.institut2c.physik.rwth-aachen.de:8123
'
),(
"
https://o.kashuba@metadata.institut2c.physik.rwth-aachen.de:8123
"
,
'
o.kashuba
'
,
'
metadata.institut2c.physik.rwth-aachen.de:8123
'
),(
"
https://metadata.institut2c.physik.rwth-aachen.de:8123
"
,
None
,
'
metadata.institut2c.physik.rwth-aachen.de:8123
'
),(
"
https://metadata.institut2c.physik.rwth-aachen.de
"
,
None
,
'
metadata.institut2c.physik.rwth-aachen.de
'
)])
def
test_parse_credentials
(
uri
,
ex_whoami
,
ex_service
):
service
,
username
=
parse_credentials
(
uri
)
assert
service
==
ex_service
assert
username
==
ex_whoami
@mark.parametrize
(
"
ex_pass
"
,
[
'
TESTpass3£$%^$%
'
,
''
,
'
any
'
])
def
test_set_get_pass
(
ex_pass
):
service
,
user
=
parse_credentials
(
"
https://metadata.institut2c.physik.rwth-aachen.de
"
)
keyring
.
set_password
(
service
,
user
,
ex_pass
)
password
=
keyring
.
get_password
(
service
,
user
)
assert
password
==
ex_pass
# @mark.parametrize("uri,ex_user,ex_host", [(
# "https://kashuba@metadata.institut2c.physik.rwth-aachen.de:8123/api/",
# 'kashuba', 'metadata.institut2c.physik.rwth-aachen.de:8123'),(
# "https://o.kashuba@metadata.institut2c.physik.rwth-aachen.de:8123",
# 'o.kashuba', 'metadata.institut2c.physik.rwth-aachen.de:8123'),(
# "https://metadata.institut2c.physik.rwth-aachen.de:8123",
# None, 'metadata.institut2c.physik.rwth-aachen.de:8123'),(
# "https://metadata.institut2c.physik.rwth-aachen.de",
# None, 'metadata.institut2c.physik.rwth-aachen.de')])
# def test_set_pass():
# print()
# user, service = parse_credentials("https://metadata.institut2c.physik.rwth-aachen.de")
# keyring.set_password(service, user, 'TESTpass3465£$%^$%111')
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment