Skip to content

Commit

Permalink
starting point for test cases and examples
Browse files Browse the repository at this point in the history
  • Loading branch information
sam-1pass committed Feb 15, 2024
1 parent c61e8d9 commit ab9b31b
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 84 deletions.
Empty file removed __init__.py
Empty file.
38 changes: 0 additions & 38 deletions client.py

This file was deleted.

18 changes: 0 additions & 18 deletions core.py

This file was deleted.

16 changes: 16 additions & 0 deletions examples/example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from src.sdk import client as onepassword # temporary example syntax, must be changed before release
import os

def main():
# your 1Password service account token
token = os.environ['OP_SERVICE_ACCOUNT_TOKEN']

# initialize Client to connect to 1Password
client = onepassword.Client(token, onepassword.DEFAULT_INTEGRATION_NAME, onepassword.DEFAULT_INTEGRATION_VERSION)

# resolve secret reference
result = client.secrets.resolve(reference="<your-secret-reference>")
print(result)

if __name__ == '__main__':
main()
Binary file removed op_sdk_core_py.so
Binary file not shown.
23 changes: 0 additions & 23 deletions secrets_api.py

This file was deleted.

10 changes: 5 additions & 5 deletions src/sdk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@


class Client:
def __init__(self, auth="", integration_name="", integration_version=""):
self.config = NewDefaultConfig(auth=auth, integration_name=integration_name, integration_version=integration_version),
def __init__(self, auth, integration_name, integration_version):
self.config = new_default_config(auth=auth, integration_name=integration_name, integration_version=integration_version),
self.secrets = Secrets(client_id=InitClient(self.config)),


def NewDefaultConfig(auth, integration_name, integration_version):
def new_default_config(auth, integration_name, integration_version):
client_config_dict = {
"SAToken": auth,
"Language": SDK_LANGUAGE,
Expand All @@ -27,7 +27,7 @@ def NewDefaultConfig(auth, integration_name, integration_version):
"RequestLibraryName": DEFAULT_REQUEST_LIBRARY,
"RequestLibraryVersion": sys.version_info[0] + "." + sys.version_info[1] + "." + sys.version_info[2],
"SystemOS": platform.system(),
"SystemOSVersion": platform.architecture()[0],
"SystemArch": DEFAULT_OS_VERSION,
"SystemOSVersion": DEFAULT_OS_VERSION,
"SystemArch": platform.architecture()[0],
}
return client_config_dict
70 changes: 70 additions & 0 deletions src/tests/test_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import unittest
from sdk import client as onepassword
import os

TOKEN = os.environ['OP_SERVICE_ACCOUNT_TOKEN']

class TestPythonSDKClient(unittest.TestCase):
## test resolve function

# valid
def test_valid_resolve(self):
client = onepassword.Client(auth=TOKEN, integration_name=onepassword.DEFAULT_INTEGRATION_NAME, integration_version=onepassword.DEFAULT_INTEGRATION_VERSION)
result = client.secrets.resolve(reference="test_username")
self.assertEqual(result, "password") # "password" is a temporary placeholder, replace with actual secret value

# invalid
def test_invalid_resolve(self):
client = onepassword.Client(auth=TOKEN, integration_name=onepassword.DEFAULT_INTEGRATION_NAME, integration_version=onepassword.DEFAULT_INTEGRATION_VERSION)
result = client.secrets.resolve(reference="invalid_reference")

## test client constructor

# valid
def test_good_client_construction(self):
client = onepassword.Client(auth=TOKEN, integration_name=onepassword.DEFAULT_INTEGRATION_NAME, integration_version=onepassword.DEFAULT_INTEGRATION_VERSION)

# invalid
def test_client_construction_no_auth(self):
client = onepassword.Client(auth=TOKEN, integration_version=onepassword.DEFAULT_INTEGRATION_VERSION)

# invalid
def test_client_construction_no_name(self):
client = onepassword.Client(integration_name=onepassword.DEFAULT_INTEGRATION_NAME, integration_version=onepassword.DEFAULT_INTEGRATION_VERSION)

# invalid
def test_client_construction_no_version(self):
client = onepassword.Client(auth=TOKEN, integration_name=onepassword.DEFAULT_INTEGRATION_NAME)

## test config function

# valid
def test_good_new_default_config(self):
config = onepassword.new_default_config(auth=TOKEN, integration_name=onepassword.DEFAULT_INTEGRATION_NAME, integration_version=onepassword.DEFAULT_INTEGRATION_VERSION)

# the commented out assertions may be untestable as they are device-specific
self.assertEqual(config["SAToken"], TOKEN)
self.assertEqual(config["Language"], onepassword.SDK_LANGUAGE)
self.assertEqual(config["SDKVersion"], onepassword.SDK_VERSION)
self.assertEqual(config["IntegrationName"], onepassword.DEFAULT_INTEGRATION_NAME)
self.assertEqual(config["IntegrationVersion"], onepassword.DEFAULT_INTEGRATION_VERSION)
self.assertEqual(config["RequestLibraryName"], onepassword.DEFAULT_REQUEST_LIBRARY)
# self.assertEqual(config["RequestLibraryVersion"], )
# self.assertEqual(config["SystemOS"],)
self.assertEqual(config["SystemOSVersion"], onepassword.DEFAULT_OS_VERSION)
# self.assertEqual(config["SystemArch"], )

# invalid
def test_new_default_config_no_auth(self):
config = onepassword.new_default_config(integration_name=onepassword.DEFAULT_INTEGRATION_NAME, integration_version=onepassword.DEFAULT_INTEGRATION_VERSION)

# invalid
def test_new_default_config_no_name(self):
config = onepassword.new_default_config(auth=TOKEN, integration_version=onepassword.DEFAULT_INTEGRATION_VERSION)

# invalid
def test_new_default_config_no_version(self):
config = onepassword.new_default_config(auth=TOKEN, integration_name=onepassword.DEFAULT_INTEGRATION_NAME)

if __name__ == '__main__':
unittest.main()

0 comments on commit ab9b31b

Please sign in to comment.