Skip to content

Commit

Permalink
Fix issue in verify and test user operations
Browse files Browse the repository at this point in the history
  • Loading branch information
ostafen committed May 22, 2024
1 parent 1e7939d commit 4610938
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 75 deletions.
149 changes: 90 additions & 59 deletions tests/immu/test_sql_verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,90 +24,121 @@
class TestVerifySQL:

def test_exec_query(self, wrappedClient: ImmuTestClient):
if(not wrappedClient.serverHigherOrEqualsToVersion("1.2.0")):
return
tabname = wrappedClient.createTestTable("id INTEGER", "name VARCHAR", "test INTEGER NOT NULL", "PRIMARY KEY (id, test)")
wrappedClient.insertToTable(tabname, ["id", "name", "test"], ["@id", "@name", "@test"], {'id': 1, 'name': 'Joe', "test": 3})
wrappedClient.insertToTable(tabname, ["id", "name", "test"], ["@id", "@name", "@test"], {'id': 2, 'name': 'Joe', "test": 2})
wrappedClient.insertToTable(tabname, ["id", "name", "test"], ["@id", "@name", "@test"], {'id': 33, 'name': 'Joe', "test": 111})
wrappedClient.insertToTable(tabname, ["id", "name", "test"], ["@id", "@name", "@test"], {'id': 3, 'name': 'Joe', "test": 1})
result = wrappedClient.simpleSelect(tabname, ["id", "name"], {'id': 1}, "id=@id")
assert(len(result) > 0)
assert(result == [(1, "Joe")])
if (not wrappedClient.serverHigherOrEqualsToVersion("1.2.0")):
return
tabname = wrappedClient.createTestTable(
"id INTEGER", "name VARCHAR", "test INTEGER NOT NULL", "PRIMARY KEY (id, test)")
wrappedClient.insertToTable(tabname, ["id", "name", "test"], [
"@id", "@name", "@test"], {'id': 1, 'name': 'Joe', "test": 3})
wrappedClient.insertToTable(tabname, ["id", "name", "test"], [
"@id", "@name", "@test"], {'id': 2, 'name': 'Joe', "test": 2})
wrappedClient.insertToTable(tabname, ["id", "name", "test"], [
"@id", "@name", "@test"], {'id': 33, 'name': 'Joe', "test": 111})
wrappedClient.insertToTable(tabname, ["id", "name", "test"], [
"@id", "@name", "@test"], {'id': 3, 'name': 'Joe', "test": 1})
result = wrappedClient.simpleSelect(
tabname, ["id", "name"], {'id': 1}, "id=@id")
assert (len(result) > 0)
assert (result == [(1, "Joe")])

ww = wrappedClient.client.verifiableSQLGet(
tabname, [datatypesv2.PrimaryKeyIntValue(1), datatypesv2.PrimaryKeyIntValue(3)]
tabname, [datatypesv2.PrimaryKeyIntValue(
1), datatypesv2.PrimaryKeyIntValue(3)]
)
assert ww.verified == True

def test_varchar(self, wrappedClient: ImmuTestClient):
if(not wrappedClient.serverHigherOrEqualsToVersion("1.2.0")):
return
tabname = wrappedClient.createTestTable("name VARCHAR[256]", "test INTEGER NOT NULL", "PRIMARY KEY (name)")
wrappedClient.insertToTable(tabname, ["name", "test"], ["@name", "@test"], {'id': 1, 'name': 'Joe', "test": 3})
wrappedClient.insertToTable(tabname, ["name", "test"], ["@name", "@test"], {'id': 2, 'name': 'Joe1', "test": 2})
wrappedClient.insertToTable(tabname, ["name", "test"], ["@name", "@test"], {'id': 33, 'name': 'Joe2', "test": 111})
wrappedClient.insertToTable(tabname, ["name", "test"], ["@name", "@test"], {'id': 3, 'name': 'Joe3', "test": 1})
result = wrappedClient.simpleSelect(tabname, ["name"], {'name': "Joe"}, "name=@name")
assert(len(result) > 0)
assert(result == [("Joe",)])
if (not wrappedClient.serverHigherOrEqualsToVersion("1.2.0")):
return
tabname = wrappedClient.createTestTable(
"name VARCHAR[128]", "test INTEGER NOT NULL", "PRIMARY KEY (name)")
wrappedClient.insertToTable(tabname, ["name", "test"], [
"@name", "@test"], {'id': 1, 'name': 'Joe', "test": 3})
wrappedClient.insertToTable(tabname, ["name", "test"], [
"@name", "@test"], {'id': 2, 'name': 'Joe1', "test": 2})
wrappedClient.insertToTable(tabname, ["name", "test"], [
"@name", "@test"], {'id': 33, 'name': 'Joe2', "test": 111})
wrappedClient.insertToTable(tabname, ["name", "test"], [
"@name", "@test"], {'id': 3, 'name': 'Joe3', "test": 1})
result = wrappedClient.simpleSelect(
tabname, ["name"], {'name': "Joe"}, "name=@name")
assert (len(result) > 0)
assert (result == [("Joe",)])

ww = wrappedClient.client.verifiableSQLGet(
tabname, [datatypesv2.PrimaryKeyVarCharValue("Joe")]
)
assert ww.verified == True

def test_boolean(self, wrappedClient: ImmuTestClient):
if(not wrappedClient.serverHigherOrEqualsToVersion("1.2.0")):
return
tabname = wrappedClient.createTestTable("name VARCHAR[256]", "test BOOLEAN NOT NULL", "PRIMARY KEY (name, test)")
wrappedClient.insertToTable(tabname, ["name", "test"], ["@name", "@test"], {'id': 1, 'name': 'Joe', "test": True})
wrappedClient.insertToTable(tabname, ["name", "test"], ["@name", "@test"], {'id': 2, 'name': 'Joe1', "test": False})
wrappedClient.insertToTable(tabname, ["name", "test"], ["@name", "@test"], {'id': 33, 'name': 'Joe2', "test": True})
wrappedClient.insertToTable(tabname, ["name", "test"], ["@name", "@test"], {'id': 3, 'name': 'Joe3', "test": False})
result = wrappedClient.simpleSelect(tabname, ["name"], {'name': "Joe"}, "name=@name")
assert(len(result) > 0)
assert(result == [("Joe",)])
if (not wrappedClient.serverHigherOrEqualsToVersion("1.2.0")):
return
tabname = wrappedClient.createTestTable(
"name VARCHAR[128]", "test BOOLEAN NOT NULL", "PRIMARY KEY (name, test)")
wrappedClient.insertToTable(tabname, ["name", "test"], [
"@name", "@test"], {'id': 1, 'name': 'Joe', "test": True})
wrappedClient.insertToTable(tabname, ["name", "test"], [
"@name", "@test"], {'id': 2, 'name': 'Joe1', "test": False})
wrappedClient.insertToTable(tabname, ["name", "test"], [
"@name", "@test"], {'id': 33, 'name': 'Joe2', "test": True})
wrappedClient.insertToTable(tabname, ["name", "test"], [
"@name", "@test"], {'id': 3, 'name': 'Joe3', "test": False})
result = wrappedClient.simpleSelect(
tabname, ["name"], {'name': "Joe"}, "name=@name")
assert (len(result) > 0)
assert (result == [("Joe",)])

ww = wrappedClient.client.verifiableSQLGet(
tabname, [datatypesv2.PrimaryKeyVarCharValue("Joe"), datatypesv2.PrimaryKeyBoolValue(True)]
tabname, [datatypesv2.PrimaryKeyVarCharValue(
"Joe"), datatypesv2.PrimaryKeyBoolValue(True)]
)
assert ww.verified == True

def test_blob(self, wrappedClient: ImmuTestClient):
if(not wrappedClient.serverHigherOrEqualsToVersion("1.2.0")):
return
tabname = wrappedClient.createTestTable("name BLOB[256]", "test BOOLEAN NOT NULL", "PRIMARY KEY (name, test)")
wrappedClient.insertToTable(tabname, ["name", "test"], ["@name", "@test"], {'id': 1, 'name': b'Joe', "test": True})
wrappedClient.insertToTable(tabname, ["name", "test"], ["@name", "@test"], {'id': 2, 'name': b'Joe1', "test": False})
wrappedClient.insertToTable(tabname, ["name", "test"], ["@name", "@test"], {'id': 33, 'name': b'Joe2', "test": True})
wrappedClient.insertToTable(tabname, ["name", "test"], ["@name", "@test"], {'id': 3, 'name': b'Joe3', "test": False})
result = wrappedClient.simpleSelect(tabname, ["name"], {'name': b"Joe"}, "name=@name")
assert(len(result) > 0)
assert(result == [(b"Joe",)])
if (not wrappedClient.serverHigherOrEqualsToVersion("1.2.0")):
return
tabname = wrappedClient.createTestTable(
"name BLOB[128]", "test BOOLEAN NOT NULL", "PRIMARY KEY (name, test)")
wrappedClient.insertToTable(tabname, ["name", "test"], [
"@name", "@test"], {'id': 1, 'name': b'Joe', "test": True})
wrappedClient.insertToTable(tabname, ["name", "test"], [
"@name", "@test"], {'id': 2, 'name': b'Joe1', "test": False})
wrappedClient.insertToTable(tabname, ["name", "test"], [
"@name", "@test"], {'id': 33, 'name': b'Joe2', "test": True})
wrappedClient.insertToTable(tabname, ["name", "test"], [
"@name", "@test"], {'id': 3, 'name': b'Joe3', "test": False})
result = wrappedClient.simpleSelect(
tabname, ["name"], {'name': b"Joe"}, "name=@name")
assert (len(result) > 0)
assert (result == [(b"Joe",)])

ww = wrappedClient.client.verifiableSQLGet(
tabname, [datatypesv2.PrimaryKeyBlobValue(b"Joe"), datatypesv2.PrimaryKeyBoolValue(True)]
tabname, [datatypesv2.PrimaryKeyBlobValue(
b"Joe"), datatypesv2.PrimaryKeyBoolValue(True)]
)
assert ww.verified == True



def test_ts(self, wrappedClient: ImmuTestClient):
if(not wrappedClient.serverHigherOrEqualsToVersion("1.2.0")):
return
if (not wrappedClient.serverHigherOrEqualsToVersion("1.2.0")):
return
now = datetime.now().astimezone(timezone.utc)
tabname = wrappedClient.createTestTable("name TIMESTAMP", "test BOOLEAN NOT NULL", "PRIMARY KEY (name, test)")
wrappedClient.insertToTable(tabname, ["name", "test"], ["@name", "@test"], {'id': 1, 'name': now, "test": True})
wrappedClient.insertToTable(tabname, ["name", "test"], ["@name", "@test"], {'id': 2, 'name': now + timedelta(seconds=1), "test": False})
wrappedClient.insertToTable(tabname, ["name", "test"], ["@name", "@test"], {'id': 33, 'name': now + timedelta(seconds=2), "test": True})
wrappedClient.insertToTable(tabname, ["name", "test"], ["@name", "@test"], {'id': 3, 'name': now + timedelta(seconds=3), "test": False})
result = wrappedClient.simpleSelect(tabname, ["name"], {'name': now}, "name=@name")
assert(len(result) > 0)
assert(result == [(now,)])
tabname = wrappedClient.createTestTable(
"name TIMESTAMP", "test BOOLEAN NOT NULL", "PRIMARY KEY (name, test)")
wrappedClient.insertToTable(tabname, ["name", "test"], [
"@name", "@test"], {'id': 1, 'name': now, "test": True})
wrappedClient.insertToTable(tabname, ["name", "test"], [
"@name", "@test"], {'id': 2, 'name': now + timedelta(seconds=1), "test": False})
wrappedClient.insertToTable(tabname, ["name", "test"], [
"@name", "@test"], {'id': 33, 'name': now + timedelta(seconds=2), "test": True})
wrappedClient.insertToTable(tabname, ["name", "test"], [
"@name", "@test"], {'id': 3, 'name': now + timedelta(seconds=3), "test": False})
result = wrappedClient.simpleSelect(
tabname, ["name"], {'name': now}, "name=@name")
assert (len(result) > 0)
assert (result == [(now,)])

ww = wrappedClient.client.verifiableSQLGet(
tabname, [datatypesv2.PrimaryKeyTsValue(int(now.timestamp()*1e6)), datatypesv2.PrimaryKeyBoolValue(True)]
tabname, [datatypesv2.PrimaryKeyTsValue(
int(now.timestamp()*1e6)), datatypesv2.PrimaryKeyBoolValue(True)]
)
assert ww.verified == True


17 changes: 1 addition & 16 deletions tests/immu/test_user_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import google.protobuf.empty_pb2
import pytest


def get_random_name(length):
return ''.join(random.choice(string.ascii_lowercase) for i in range(length))

Expand Down Expand Up @@ -48,28 +49,14 @@ def test_users_functions(self, client: ImmudbClient):
except grpc.RpcError as e:
assert e.details() == 'user already exists'

user1 = "test_"+get_random_name(8)
password = "Pw0:"+get_random_string(12)
database = "defaultdb"
permission = immudb.constants.PERMISSION_RW

try:
resp = client.createUser(user1, "12345", permission, database)
assert False # it is not allowed to create a trivial password
except grpc.RpcError as e:
pass

try:
resp = client.createUser(user1, "12345", permission, database)
assert False # it is not allowed to create a trivial password
except grpc.RpcError as e:
pass

newPassword = "Pw1:"+get_random_string(12)
resp = client.changePassword(user, newPassword, password)
assert type(resp.reply) == google.protobuf.empty_pb2.Empty


with pytest.raises(RpcError):
assert client.setActiveUser(True, "not existing user") == True

Expand All @@ -81,8 +68,6 @@ def test_users_functions(self, client: ImmudbClient):
with pytest.raises(RpcError):
client.login(user, newPassword)


assert client.setActiveUser(True, user) == True
# User again active
client.login(user, newPassword)

0 comments on commit 4610938

Please sign in to comment.