From 461093840a986ec91f446d570934e49ff3741c13 Mon Sep 17 00:00:00 2001 From: Stefano Scafiti Date: Wed, 22 May 2024 22:46:20 +0200 Subject: [PATCH] Fix issue in verify and test user operations --- tests/immu/test_sql_verify.py | 149 +++++++++++++++++------------ tests/immu/test_user_operations.py | 17 +--- 2 files changed, 91 insertions(+), 75 deletions(-) diff --git a/tests/immu/test_sql_verify.py b/tests/immu/test_sql_verify.py index b77c028..776ede3 100644 --- a/tests/immu/test_sql_verify.py +++ b/tests/immu/test_sql_verify.py @@ -24,33 +24,46 @@ 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")] @@ -58,56 +71,74 @@ def test_varchar(self, wrappedClient: ImmuTestClient): 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 - - diff --git a/tests/immu/test_user_operations.py b/tests/immu/test_user_operations.py index e6ef1bf..95ae61e 100644 --- a/tests/immu/test_user_operations.py +++ b/tests/immu/test_user_operations.py @@ -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)) @@ -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 @@ -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) -