-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
starting point for test cases and examples
- Loading branch information
Showing
3 changed files
with
88 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |