Skip to content
Snippets Groups Projects
Commit ceed44de authored by Alex Kashuba's avatar Alex Kashuba
Browse files

Tested keyring set/get

parent b49e1d02
No related branches found
No related tags found
No related merge requests found
from urllib.parse import urlparse
import getpass
import sys
def parseurl(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.
......
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment