Skip to content

Commit

Permalink
Merge pull request #2 from phasehq/misc-cleanup
Browse files Browse the repository at this point in the history
feat: add pyproject toml, clean up imports
  • Loading branch information
nimish-ks authored May 30, 2023
2 parents a1b1685 + a931150 commit f558f36
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 24 deletions.
29 changes: 29 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[build-system]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"

[project]
name = "phase_dev"
version = "0.0.1"
description = "Python SDK for Phase"
readme = "README.md"
requires-python = ">=3.10"
classifiers = [
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
]
authors = [
{ name = "Phase", email = "[email protected]" }
]
dependencies = [
"pyNaCl >= 1.4.0",
"requests >= 2.26.0",
]

[project.optional-dependencies]
dev = ["pip-tools", "pytest"]

[project.urls]
"Homepage" = "https://phase.dev"
"Documentation" = "https://docs.phase.dev"
16 changes: 0 additions & 16 deletions setup.py

This file was deleted.

File renamed without changes.
2 changes: 1 addition & 1 deletion src/phase.py → src/phase/phase.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import re
from nacl.bindings import crypto_kx_server_session_keys, crypto_kx_client_session_keys
from dataclasses import dataclass
from src.utils.crypto import decrypt_b64, encrypt_b64, fetch_app_key, random_key_pair, reconstruct_secret
from .utils.crypto import decrypt_b64, encrypt_b64, fetch_app_key, random_key_pair, reconstruct_secret
from .version import __version__, __ph_version__


Expand Down
Empty file added src/phase/utils/__init__.py
Empty file.
File renamed without changes.
File renamed without changes.
9 changes: 4 additions & 5 deletions tests/test_decrypt.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import pytest
from src.phase import Phase
import src
from src.phase.phase import Phase

APP_ID = "phApp:v1:e0e50cb9a1953c610126b4092093b1beca51d08d91fc3d9f8d90482a32853215"
APP_SECRET = "pss:v1:d261abecb6708c18bebdb8b2748ee574e2b0bdeaf19b081a5f10006cc83d48d0:d146c8c6d326a7842ff9b2da0da455b3f7f568a70808e2eb0cfc5143d4fe170f:59e413612e06d75d251e3416361d0743345a9c9eda1cbcf2b1ef16e3077c011c"
Expand All @@ -19,7 +18,7 @@ def mock_fetch_app_key(appToken, wrapKey, appId, dataSize):
def test_phase_decrypt_returns_correct_plaintext(phase_instance, monkeypatch):
data = "Signal"

monkeypatch.setattr(src.phase, "fetch_app_key", mock_fetch_app_key)
monkeypatch.setattr("src.phase.phase.fetch_app_key", mock_fetch_app_key)

ciphertext = phase_instance.encrypt(data)

Expand All @@ -29,10 +28,10 @@ def test_phase_decrypt_returns_correct_plaintext(phase_instance, monkeypatch):
assert plaintext == data


def test_phase_decrypt_rejects_promise_with_incorrect_app_secret(monkeypatch):
def test_phase_decrypt_fails_with_incorrect_app_secret(monkeypatch):
phase = Phase(APP_ID, APP_SECRET_INVALID)

monkeypatch.setattr(src.phase, "fetch_app_key", mock_fetch_app_key)
monkeypatch.setattr("src.phase.phase.fetch_app_key", mock_fetch_app_key)

data = "Signal"
ciphertext = phase.encrypt(data)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ def phase_instance():
return Phase(APP_ID_INVALID, APP_SECRET_INVALID)


def test_invalid_app_id(phase_instance):
def test_init_fails_with_invalid_app_id(phase_instance):
invalid_app_id = "phApp:version:cd2d579490fd794f1640590220de86a3676fa7979d419056bc631741b320b701"
with pytest.raises(ValueError, match="Invalid Phase APP_ID"):
Phase(invalid_app_id, APP_SECRET_INVALID)


def test_invalid_app_secret(phase_instance):
def test_test_init_fails_with_invalid_app_secret(phase_instance):
invalid_app_secret = "pss:v1:00000000000000000000000000000000:00000000000000000000000000000000:00000000000000000000000000000000"
with pytest.raises(ValueError, match="Invalid Phase APP_SECRET"):
Phase(APP_ID_INVALID, invalid_app_secret)

0 comments on commit f558f36

Please sign in to comment.