Example #1
0
 def __init__(self, server_name: str = None):
     self.server_name = server_name or (
         "server-" + randstring(length=4, alphabet=string.ascii_letters))
     self.sharing_root_d: Optional[Path] = None
     self.sharing_root_d2: Optional[Path] = None
     self.sharing_root_f: Optional[Path] = None
     self._daemon = None
Example #2
0
def test_consecutive_scrypt_different():
    plaintext = randstring()

    auth_enc1 = AuthScrypt.new(plaintext)
    auth_enc2 = AuthScrypt.new(plaintext)

    # Two consecutive creations should be different
    assert str(auth_enc1) != str(auth_enc2)
Example #3
0
def tmpdir(parent, *, create=True, name=None, prefix=None) -> Path:
    if name is None:
        if prefix is None:
            prefix = "dir-"
        name = (prefix + randstring(length=4))
    d = Path(parent) / name
    if create:
        log.x("TEST", f"Creating DIR '{d}'")
        d.mkdir(parents=True, exist_ok=True)
    return d
Example #4
0
def test_scrypt_auth():
    plaintext = randstring()

    auth_enc1 = AuthScrypt.new(plaintext)

    auth_str = str(auth_enc1)
    auth_dec = AuthFactory.parse(auth_str)

    # Match against plaintext
    assert auth_dec.authenticate(plaintext)
Example #5
0
def test_scrypt_parse():
    plaintext = randstring()

    auth_enc1 = AuthScrypt.new(plaintext)

    auth_str = str(auth_enc1)
    auth_dec = AuthFactory.parse(auth_str)

    # Are we parsing correctly?
    assert str(auth_dec) == auth_str
Example #6
0
def tmpfile(parent, *, create=True, name=None, size: int = None) -> Path:
    if name is None:
        name = ("file-" + randstring(length=4))
    f = Path(parent) / name
    if create:
        log.x("TEST", f"Creating FILE '{f}'")
        f.touch()
        if size is None:
            size = randint(0, 1024)
        f.write_bytes(os.urandom(size))
    return f
Example #7
0
def test_scrypt():
    m = randstring()

    salt_bin, hash_bin = scrypt_new(m, salt_length=48)
    hash_b2 = scrypt(m, salt_bin)

    assert hash_bin == hash_b2

    salt_s = bytes_to_b64(salt_bin)
    hash_b3 = scrypt(m, salt_s)

    assert hash_bin == hash_b3
def test_rmkdir():
    with EsConnectionTest(esd.sharing_root.name) as client:
        r = randstring()
        client.execute_command(Commands.REMOTE_CREATE_DIRECTORY, r)
        assert (esd.sharing_root / r).exists()
        client.execute_command(Commands.REMOTE_REMOVE, r)
Example #9
0
def test_plain_auth():
    plaintext = randstring()

    # Plain auth check
    assert (AuthFactory.parse(plaintext).authenticate(plaintext))
Example #10
0
 def __init__(self, sock: SocketTcp):
     self.socket: SocketTcp = sock
     self.stream = TcpStream(sock)
     self.endpoint: Optional[Endpoint] = sock.remote_endpoint()
     self.tag = randstring(
         4, alphabet=string.ascii_lowercase)  # not an unique id, just a tag