mirror of
https://github.com/alexgo-io/stacks-puppet-node.git
synced 2026-04-14 12:06:42 +08:00
remove internal API tests, since they're removed in 0.19
This commit is contained in:
@@ -70,6 +70,7 @@ class APITestCase(unittest.TestCase):
|
||||
def __init__(self, methodName):
|
||||
super(APITestCase, self).__init__(methodName)
|
||||
self.app = ForwardingClient("http://localhost:6270")
|
||||
|
||||
def get_request(self, endpoint, headers={}, status_code=200,
|
||||
no_json = False):
|
||||
t_start = time.time()
|
||||
@@ -127,103 +128,22 @@ def check_data(cls, data, required_keys={}):
|
||||
if type(required_keys[k]) == int:
|
||||
cls.assertGreaterEqual(data[k], required_keys[k])
|
||||
|
||||
|
||||
class PingTest(APITestCase):
|
||||
def test_found_user_lookup(self):
|
||||
def test_ping(self):
|
||||
data = self.get_request("/v1/ping",
|
||||
headers = {} , status_code=200)
|
||||
|
||||
self.assertTrue(data['status'] == 'alive')
|
||||
self.assertTrue('version' in data)
|
||||
|
||||
class AuthInternal(APITestCase):
|
||||
def test_get_and_use_session_token_domain(self):
|
||||
privkey = ("a28ea1a6f11fb1c755b1d102990d64d6" +
|
||||
"b4468c10705bbcbdfca8bc4497cf8da8")
|
||||
def test_node_ping(self):
|
||||
data = self.get_request("/v1/node/ping",
|
||||
headers = {} , status_code=200)
|
||||
|
||||
# test support for the development UI port as well (3000)
|
||||
auth_header = get_auth_header(port = 3000)
|
||||
request = {
|
||||
'app_domain': 'test.com',
|
||||
'app_public_key': blockstack_client.keys.get_pubkey_hex(privkey),
|
||||
'methods': ['wallet_read', 'user_read'],
|
||||
}
|
||||
self.assertTrue(data['status'] == 'alive')
|
||||
self.assertTrue('version' in data)
|
||||
|
||||
signer = jsontokens.TokenSigner()
|
||||
package = signer.sign(request, privkey)
|
||||
|
||||
url = "/v1/auth?authRequest={}".format(package)
|
||||
data = self.get_request(url, headers = auth_header, status_code=200)
|
||||
|
||||
self.assertIn('token', data)
|
||||
session = data['token']
|
||||
|
||||
auth_header = get_auth_header(session)
|
||||
|
||||
# test wrong origin
|
||||
data = self.get_request('/v1/wallet/payment_address',
|
||||
headers = auth_header, status_code=403)
|
||||
# test correct origin
|
||||
auth_header['Origin'] = 'http://test.com'
|
||||
data = self.get_request('/v1/wallet/payment_address',
|
||||
headers = auth_header, status_code=200)
|
||||
|
||||
# self.assertIn('error', data)
|
||||
|
||||
def test_get_and_use_session_token_url(self):
|
||||
privkey = ("a28ea1a6f11fb1c755b1d102990d64d6" +
|
||||
"b4468c10705bbcbdfca8bc4497cf8da8")
|
||||
|
||||
# test support for the development UI port as well (3000)
|
||||
auth_header = get_auth_header(port = 3000)
|
||||
request = {
|
||||
'app_domain': 'http://test.com',
|
||||
'app_public_key': blockstack_client.keys.get_pubkey_hex(privkey),
|
||||
'methods': ['wallet_read', 'user_read'],
|
||||
}
|
||||
|
||||
signer = jsontokens.TokenSigner()
|
||||
package = signer.sign(request, privkey)
|
||||
|
||||
url = "/v1/auth?authRequest={}".format(package)
|
||||
data = self.get_request(url, headers = auth_header, status_code=200)
|
||||
|
||||
self.assertIn('token', data)
|
||||
session = data['token']
|
||||
|
||||
auth_header = get_auth_header(session)
|
||||
|
||||
# test wrong origin
|
||||
data = self.get_request('/v1/wallet/payment_address',
|
||||
headers = auth_header, status_code=403)
|
||||
# test correct origin
|
||||
auth_header['Origin'] = 'http://test.com'
|
||||
data = self.get_request('/v1/wallet/payment_address',
|
||||
headers = auth_header, status_code=200)
|
||||
|
||||
def test_auth_token_no_username(self):
|
||||
auth_header = get_auth_header()
|
||||
|
||||
test_string = "eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NksifQ.eyJhcHBfZG9tYWluIjoiaGVsbG9ibG9ja3N0YWNrLmNvbSIsIm1ldGhvZHMiOltdLCJhcHBfcHVibGljX2tleSI6IjAyYjk0ZjY4NDgzOGFkMjdmZTE0Nzk1MGMyNjQ1ZjRhYzhjYmU1OTJlYjYzYmQwYTQ5MWQ2YzBlYWZjNjE0YzVjMCJ9.0lLrxt8uGtB2rCKB9sb0jK1DdrrWuuuWM-nsyjvFnmjNx0XfG14Npl72w6hp9W2OHoXdPe7VuXkfvKmVNlQdeA"
|
||||
|
||||
url = "/v1/auth?authRequest={}".format(test_string)
|
||||
data = self.get_request(url, headers = auth_header, status_code=200)
|
||||
self.assertIn('token', data)
|
||||
|
||||
def test_auth_new_token_no_username_issue483(self):
|
||||
auth_header = get_auth_header()
|
||||
test_string = "eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NksifQ.eyJ2ZXJzaW9uIjoxLCJibG9ja2NoYWluX2lkIjpudWxsLCJhcHBfcHJpdmF0ZV9rZXkiOiIxNDYwYWIyY2RjZmE1NDQwNzc5YWYwZDA0NWIzZTFlMjE5MjY4OGRjZTA5NDk4YWMyNDBkMTdjNzA2YWRiOThkIiwiYXBwX2RvbWFpbiI6Imh0dHA6Ly9sb2NhbGhvc3Q6NTAwMCIsIm1ldGhvZHMiOlsiIl0sImFwcF9wdWJsaWNfa2V5cyI6W3sicHVibGljX2tleSI6IjAzYTJhZmYyODhlYjI1NzVjZjE3ZTBjODc0NDZlNWExMDdmOTFkZjMzMjk5MjNkNDNmMDhmYTFmNzdlZDE0MTNmMCIsImRldmljZV9pZCI6IjAifV0sImRldmljZV9pZCI6IjAifQ.-uT-lOrvQDBZJWdg8p53LmEYBw1C8dVyGSAn96nR49MGSlNXP0vD7JsasjI6cbn9JSqGPFq1EpPLaHACkmyMcQ"
|
||||
url = "/v1/auth?authRequest={}".format(test_string)
|
||||
data = self.get_request(url, headers = auth_header, status_code=200)
|
||||
self.assertIn('token', data)
|
||||
|
||||
class UsersInternal(APITestCase):
|
||||
def test_get_users(self):
|
||||
user = "muneeb.id"
|
||||
data = self.get_request('/v1/users/{}'.format(user),
|
||||
headers = get_auth_header(), status_code=200)
|
||||
to_check = {
|
||||
"@type": True,
|
||||
}
|
||||
check_data(self, data, to_check)
|
||||
|
||||
class LookupUsersTest(APITestCase):
|
||||
def test_found_user_lookup(self):
|
||||
@@ -250,6 +170,7 @@ class LookupUsersTest(APITestCase):
|
||||
data = self.get_request("/v1/names?page=10000",
|
||||
headers = {} , status_code=200)
|
||||
|
||||
|
||||
class Zonefiles(APITestCase):
|
||||
def test_get_zonefile(self):
|
||||
zf_url = '/v1/names/{}/zonefile'
|
||||
@@ -266,6 +187,7 @@ class Zonefiles(APITestCase):
|
||||
self.assertEqual(zf_data_historic_lookup['zonefile'],
|
||||
zf_data['zonefile'])
|
||||
|
||||
|
||||
class NameHistoryTest(APITestCase):
|
||||
def build_url(self, username):
|
||||
return '/v1/names/{}/history'.format(username)
|
||||
@@ -298,6 +220,7 @@ class NamesOwnedTest(APITestCase):
|
||||
self.assertTrue(len(data["names"]) > 0)
|
||||
self.assertIn(name, data["names"])
|
||||
|
||||
|
||||
class NamespaceTest(APITestCase):
|
||||
def test_id_space(self):
|
||||
data = self.get_request("/v1/namespaces",
|
||||
@@ -374,74 +297,11 @@ class BlockChains(APITestCase):
|
||||
"value_hash": schemas.OP_HEX_PATTERN}
|
||||
check_data(self, data[0], to_check)
|
||||
|
||||
class BlockChainsInternal(APITestCase):
|
||||
def test_unspents(self):
|
||||
url = "/v1/blockchains/bitcoin/{}/unspent".format(DEFAULT_WALLET_ADDRESS)
|
||||
self.get_request(url, headers = {}, status_code = 403)
|
||||
data = self.get_request(url, headers = get_auth_header(), status_code = 200)
|
||||
|
||||
self.assertTrue(len(data) >= 1)
|
||||
data = data[0]
|
||||
|
||||
self.assertTrue(data['confirmations'] >= 0)
|
||||
self.assertRegexpMatches(data['out_script'], schemas.OP_HEX_PATTERN)
|
||||
self.assertRegexpMatches(data['outpoint']['hash'], schemas.OP_HEX_PATTERN)
|
||||
self.assertRegexpMatches(data['transaction_hash'], schemas.OP_HEX_PATTERN)
|
||||
self.assertTrue(data['value'] >= 0)
|
||||
def test_txs(self):
|
||||
url = "/v1/blockchains/bitcoin/txs".format(DEFAULT_WALLET_ADDRESS)
|
||||
self.post_request(url, payload = {}, headers = {}, status_code = 403)
|
||||
self.post_request(url, payload = {}, headers = get_auth_header(), status_code = 401)
|
||||
|
||||
class WalletInternal(APITestCase):
|
||||
def test_addresses(self):
|
||||
for endpoint in ['payment_address', 'owner_address']:
|
||||
data = self.get_request("/v1/wallet/{}".format(endpoint),
|
||||
headers = get_auth_header(), status_code = 200)
|
||||
self.assertRegexpMatches(data['address'], schemas.OP_ADDRESS_PATTERN)
|
||||
data = self.get_request("/v1/wallet/data_pubkey",
|
||||
headers = get_auth_header(), status_code = 200)
|
||||
self.assertRegexpMatches(data['public_key'], schemas.OP_PUBKEY_PATTERN)
|
||||
def test_balance(self):
|
||||
data = self.get_request("/v1/wallet/balance",
|
||||
headers = get_auth_header(), status_code = 200)
|
||||
to_check = {'balance' : { 'bitcoin' : 0, 'satoshis' : 0 } }
|
||||
check_data(self, data, to_check)
|
||||
def test_keys(self):
|
||||
data = self.get_request("/v1/wallet/keys",
|
||||
headers = get_auth_header(), status_code = 200)
|
||||
to_check = {
|
||||
"data_privkey": schemas.OP_HEX_PATTERN,
|
||||
"data_pubkey": schemas.OP_PUBKEY_PATTERN,
|
||||
"owner_address": schemas.OP_ADDRESS_PATTERN,
|
||||
"owner_privkey": True,
|
||||
"payment_address": schemas.OP_ADDRESS_PATTERN,
|
||||
"payment_privkey": True,
|
||||
}
|
||||
|
||||
check_data(self, data, to_check)
|
||||
|
||||
class NodeInternal(APITestCase):
|
||||
def test_registrar(self):
|
||||
self.get_request("/v1/node/registrar/state", headers = get_auth_header(),
|
||||
status_code = 200)
|
||||
def test_get_log(self):
|
||||
self.get_request("/v1/node/log", headers = get_auth_header(),
|
||||
status_code = 200, no_json = True)
|
||||
def test_config(self):
|
||||
data = self.get_request("/v1/node/config", headers = get_auth_header(),
|
||||
status_code = 200)
|
||||
to_check = { "bitcoind": True,
|
||||
"blockchain-reader": True,
|
||||
"blockchain-writer": True,
|
||||
"blockstack-client": True }
|
||||
|
||||
check_data(self, data, to_check)
|
||||
|
||||
def test_main(args = []):
|
||||
test_classes = [PingTest, LookupUsersTest, NamespaceTest, BlockChains,
|
||||
Prices, NamesOwnedTest, NameHistoryTest,
|
||||
AuthInternal, BlockChainsInternal, Zonefiles, WalletInternal, NodeInternal]
|
||||
Prices, NamesOwnedTest, NameHistoryTest, Zonefiles]
|
||||
|
||||
test_map = {}
|
||||
for t in test_classes:
|
||||
|
||||
Reference in New Issue
Block a user