Exemple #1
0
def set_device_pairing_code(context):
    pairing_data = dict(code='ABC123',
                        state='this is a state',
                        token='this is a token',
                        expiration=84600)
    cache = SeleneCache()
    cache.set_with_expiration('pairing.code:ABC123',
                              json.dumps(pairing_data),
                              expiration=86400)
    context.pairing_data = pairing_data
    context.pairing_code = 'ABC123'
def set_device_pairing_code(context):
    pairing_data = dict(
        code="ABC123",
        state="this is a state",
        token="this is a token",
        expiration=84600,
    )
    cache = SeleneCache()
    cache.set_with_expiration("pairing.code:ABC123",
                              json.dumps(pairing_data),
                              expiration=86400)
    context.pairing_data = pairing_data
    context.pairing_code = "ABC123"
Exemple #3
0
def set_device_pairing_code(context):
    """Add dummy data to the Redis cache for the test."""
    pairing_data = dict(
        code="ABC123",
        packaging_type="pantacor",
        state="this is a state",
        token="this is a token",
        expiration=84600,
    )
    cache = SeleneCache()
    cache.set_with_expiration("pairing.code:ABC123",
                              json.dumps(pairing_data),
                              expiration=86400)
    context.pairing_data = pairing_data
    context.pairing_code = "ABC123"
def generate_device_login(device_id: str, cache: SeleneCache) -> dict:
    """Generates a login session for a given device id"""
    sha512 = hashlib.sha512()
    sha512.update(bytes(str(uuid.uuid4()), "utf-8"))
    access = sha512.hexdigest()
    sha512.update(bytes(str(uuid.uuid4()), "utf-8"))
    refresh = sha512.hexdigest()
    login = dict(uuid=device_id,
                 accessToken=access,
                 refreshToken=refresh,
                 expiration=ONE_DAY)
    login_json = json.dumps(login)
    # Storing device access token for one:
    cache.set_with_expiration(
        "device.token.access:{access}".format(access=access), login_json,
        ONE_DAY)
    # Storing device refresh token for ever:
    cache.set("device.token.refresh:{refresh}".format(refresh=refresh),
              login_json)

    # Storing the login session by uuid (that allows us to delete session using the uuid)
    cache.set("device.session:{uuid}".format(uuid=device_id), login_json)
    return login