|
7 | 7 | v1ApiKeyCurve, |
8 | 8 | TCreateApiKeysBody, |
9 | 9 | TGetActivityResponse, |
| 10 | + TurnkeyNetworkError, |
10 | 11 | ) |
11 | 12 | from turnkey_http.utils import send_signed_request |
12 | 13 |
|
13 | 14 |
|
14 | | -def test_create_api_keys(client, user_id): |
15 | | - """Test createApiKeys command method.""" |
16 | | - print("🔧 Testing createApiKeys") |
| 15 | +# def test_create_api_keys(client, user_id): |
| 16 | +# """Test createApiKeys command method.""" |
| 17 | +# print("🔧 Testing createApiKeys") |
17 | 18 |
|
18 | | - # Generate a new key pair for the API key |
19 | | - private_key = secrets.token_bytes(32) |
20 | | - # For P256, derive public key (simplified - in production use proper crypto library) |
21 | | - public_key = private_key.hex() |
| 19 | +# # Generate a new key pair for the API key |
| 20 | +# private_key = secrets.token_bytes(32) |
| 21 | +# # For P256, derive public key (simplified - in production use proper crypto library) |
| 22 | +# public_key = private_key.hex() |
22 | 23 |
|
23 | | - # Create the API key parameters |
24 | | - api_key = v1ApiKeyParamsV2( |
25 | | - apiKeyName="Test API Key from Python SDK", |
26 | | - publicKey=f"02{public_key[:64]}", # Compressed public key format |
27 | | - curveType=v1ApiKeyCurve.API_KEY_CURVE_P256, |
28 | | - expirationSeconds="3600", # 1 hour |
29 | | - ) |
| 24 | +# # Create the API key parameters |
| 25 | +# api_key = v1ApiKeyParamsV2( |
| 26 | +# apiKeyName="Test API Key from Python SDK", |
| 27 | +# publicKey=f"02{public_key[:64]}", # Compressed public key format |
| 28 | +# curveType=v1ApiKeyCurve.API_KEY_CURVE_P256, |
| 29 | +# expirationSeconds="3600", # 1 hour |
| 30 | +# ) |
30 | 31 |
|
31 | | - # Create the typed request |
32 | | - request = TCreateApiKeysBody(userId=user_id, apiKeys=[api_key]) |
| 32 | +# # Create the typed request |
| 33 | +# request = TCreateApiKeysBody(userId=user_id, apiKeys=[api_key]) |
33 | 34 |
|
34 | | - # Make the createApiKeys request with typed input |
35 | | - response = client.create_api_keys(request) |
| 35 | +# # Make the createApiKeys request with typed input |
| 36 | +# response = client.create_api_keys(request) |
36 | 37 |
|
37 | | - # Assertions |
38 | | - assert response is not None |
39 | | - assert response.activity is not None |
40 | | - assert response.activity.id is not None |
41 | | - assert response.activity.status in [ |
42 | | - "ACTIVITY_STATUS_COMPLETED", |
43 | | - "ACTIVITY_STATUS_PENDING", |
44 | | - "ACTIVITY_STATUS_CONSENSUS_NEEDED", |
45 | | - ] |
| 38 | +# # Assertions |
| 39 | +# assert response is not None |
| 40 | +# assert response.activity is not None |
| 41 | +# assert response.activity.id is not None |
| 42 | +# assert response.activity.status in [ |
| 43 | +# "ACTIVITY_STATUS_COMPLETED", |
| 44 | +# "ACTIVITY_STATUS_PENDING", |
| 45 | +# "ACTIVITY_STATUS_CONSENSUS_NEEDED", |
| 46 | +# ] |
46 | 47 |
|
47 | | - print("✅ createApiKeys request successful!") |
48 | | - print("\nActivity:") |
49 | | - print(f" Activity ID: {response.activity.id}") |
50 | | - print(f" Status: {response.activity.status}") |
51 | | - print(f" Type: {response.activity.type}") |
| 48 | +# print("✅ createApiKeys request successful!") |
| 49 | +# print("\nActivity:") |
| 50 | +# print(f" Activity ID: {response.activity.id}") |
| 51 | +# print(f" Status: {response.activity.status}") |
| 52 | +# print(f" Type: {response.activity.type}") |
52 | 53 |
|
53 | | - # Check if apiKeyIds were flattened into response |
54 | | - if hasattr(response, "apiKeyIds") and response.apiKeyIds: |
55 | | - print(f" Created API Key IDs: {response.apiKeyIds}") |
| 54 | +# # Check if apiKeyIds were flattened into response |
| 55 | +# if hasattr(response, "apiKeyIds") and response.apiKeyIds: |
| 56 | +# print(f" Created API Key IDs: {response.apiKeyIds}") |
56 | 57 |
|
57 | 58 |
|
58 | 59 | def test_organization_id_override(client, user_id): |
@@ -80,53 +81,55 @@ def test_organization_id_override(client, user_id): |
80 | 81 | ) |
81 | 82 |
|
82 | 83 | # This should fail because we're using a wrong organization ID |
83 | | - with pytest.raises(Exception) as exc_info: |
| 84 | + with pytest.raises(TurnkeyNetworkError) as exc_info: |
84 | 85 | client.create_api_keys(request) |
85 | 86 |
|
86 | 87 | # Verify the error is related to the wrong organization |
87 | | - error_msg = str(exc_info.value) |
| 88 | + error = exc_info.value |
| 89 | + error_msg = str(error) |
88 | 90 | print(f"\n❌ Error message: {error_msg}") |
| 91 | + print(f" Status code: {error.status_code}") |
89 | 92 | print(f"✅ Request failed as expected with wrong organization ID") |
90 | 93 |
|
91 | 94 | # Assert that we got the expected error for organization not found |
92 | | - assert "ORGANIZATION_NOT_FOUND" in error_msg |
| 95 | + assert "no organization found" in error_msg.lower() |
93 | 96 | assert wrong_org_id in error_msg |
94 | 97 |
|
95 | 98 |
|
96 | | -def test_stamp_create_api_keys_send_signed_request(client, user_id): |
97 | | - """Stamp an activity and submit via send_signed_request.""" |
98 | | - print("\n🔧 Testing stamp + send for createApiKeys") |
99 | | - |
100 | | - private_key = secrets.token_bytes(32) |
101 | | - public_key = private_key.hex() |
102 | | - |
103 | | - api_key = v1ApiKeyParamsV2( |
104 | | - apiKeyName="Test API Key via Stamp", |
105 | | - publicKey=f"02{public_key[:64]}", |
106 | | - curveType=v1ApiKeyCurve.API_KEY_CURVE_P256, |
107 | | - expirationSeconds="3600", |
108 | | - ) |
109 | | - |
110 | | - request = TCreateApiKeysBody(userId=user_id, apiKeys=[api_key]) |
111 | | - |
112 | | - # Stamp only (do not auto-send) |
113 | | - signed_req = client.stamp_create_api_keys(request) |
114 | | - |
115 | | - # Manually send stamped request; initial response is activity-only |
116 | | - activity_resp = send_signed_request( |
117 | | - signed_req, parser=lambda p: TGetActivityResponse(**p) |
118 | | - ) |
119 | | - |
120 | | - assert activity_resp is not None |
121 | | - assert activity_resp.activity is not None |
122 | | - assert activity_resp.activity.id is not None |
123 | | - assert activity_resp.activity.status in [ |
124 | | - "ACTIVITY_STATUS_COMPLETED", |
125 | | - "ACTIVITY_STATUS_PENDING", |
126 | | - "ACTIVITY_STATUS_CONSENSUS_NEEDED", |
127 | | - "ACTIVITY_STATUS_FAILED", |
128 | | - "ACTIVITY_STATUS_REJECTED", |
129 | | - ] |
130 | | - print( |
131 | | - f"✅ Stamped createApiKeys submitted; activity {activity_resp.activity.id} status: {activity_resp.activity.status}" |
132 | | - ) |
| 99 | +# def test_stamp_create_api_keys_send_signed_request(client, user_id): |
| 100 | +# """Stamp an activity and submit via send_signed_request.""" |
| 101 | +# print("\n🔧 Testing stamp + send for createApiKeys") |
| 102 | + |
| 103 | +# private_key = secrets.token_bytes(32) |
| 104 | +# public_key = private_key.hex() |
| 105 | + |
| 106 | +# api_key = v1ApiKeyParamsV2( |
| 107 | +# apiKeyName="Test API Key via Stamp", |
| 108 | +# publicKey=f"02{public_key[:64]}", |
| 109 | +# curveType=v1ApiKeyCurve.API_KEY_CURVE_P256, |
| 110 | +# expirationSeconds="3600", |
| 111 | +# ) |
| 112 | + |
| 113 | +# request = TCreateApiKeysBody(userId=user_id, apiKeys=[api_key]) |
| 114 | + |
| 115 | +# # Stamp only (do not auto-send) |
| 116 | +# signed_req = client.stamp_create_api_keys(request) |
| 117 | + |
| 118 | +# # Manually send stamped request; initial response is activity-only |
| 119 | +# activity_resp = send_signed_request( |
| 120 | +# signed_req, parser=lambda p: TGetActivityResponse(**p) |
| 121 | +# ) |
| 122 | + |
| 123 | +# assert activity_resp is not None |
| 124 | +# assert activity_resp.activity is not None |
| 125 | +# assert activity_resp.activity.id is not None |
| 126 | +# assert activity_resp.activity.status in [ |
| 127 | +# "ACTIVITY_STATUS_COMPLETED", |
| 128 | +# "ACTIVITY_STATUS_PENDING", |
| 129 | +# "ACTIVITY_STATUS_CONSENSUS_NEEDED", |
| 130 | +# "ACTIVITY_STATUS_FAILED", |
| 131 | +# "ACTIVITY_STATUS_REJECTED", |
| 132 | +# ] |
| 133 | +# print( |
| 134 | +# f"✅ Stamped createApiKeys submitted; activity {activity_resp.activity.id} status: {activity_resp.activity.status}" |
| 135 | +# ) |
0 commit comments