Example #1
0
def before_all(context):
    context.server_url = SERVER_URL.rstrip("/")
    context.session = Session()
    context.print_url = PRINT_URL
    context.print_payload = PRINT_PAYLOAD
    context.print_headers = PRINT_HEADERS
    context.template_variables = {}
Example #2
0
def before_all(context):
    context.server_url = SERVER_URL.rstrip('/')
    context.session = Session()
    context.print_url = PRINT_URL
    context.print_payload = PRINT_PAYLOAD
    context.print_headers = PRINT_HEADERS
    context.template_variables = {}
Example #3
0
from requests import Session
from urllib.parse import urljoin
import hashlib
import hmac
import json

from settings import SERVER_URL, ADMIN_LOGIN, ADMIN_PASS

SERVER_URL = SERVER_URL.rstrip('/')


class ApiAuthException(Exception):
    pass


def hash_token(username, password, token):
    sha_password = hashlib.sha512(password.encode()).hexdigest()
    hashed_username = hmac.new(
        username.encode(),
        sha_password.encode(),
        hashlib.sha512
    ).hexdigest()
    hashed_token = hmac.new(
        bytes(hashed_username.encode()),
        bytes(token.encode()),
        hashlib.sha512
    ).hexdigest()
    return hashed_token


def get_token(username=ADMIN_LOGIN, password=ADMIN_PASS, session=None):