Skip to content
This repository was archived by the owner on Oct 9, 2023. It is now read-only.

Commit c50bb05

Browse files
author
James Williams
authored
Define user password expiry in terms of seconds (#288)
## What is the goal of this PR? We've redefined the way we expose how long until a password expires in seconds, rather than days as was done previously. ## What are the changes implemented in this PR? * We've changed `password_expiry_days` to `password_expiry_seconds`. * We implement the newly updated BDD steps to do with opening and closing connections, and prepare other steps for booting and configuring TypeDB for use once the TypeDB runner is available in Python
1 parent 376aa6b commit c50bb05

File tree

14 files changed

+218
-84
lines changed

14 files changed

+218
-84
lines changed

.factory/automation.yml

+30-29
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,20 @@ build:
6363
export ARTIFACT_USERNAME=$REPO_VATICLE_USERNAME
6464
export ARTIFACT_PASSWORD=$REPO_VATICLE_PASSWORD
6565
bazel run @vaticle_dependencies//distribution/artifact:create-netrc
66-
.factory/test-core.sh //tests/behaviour/connection/... --test_output=errors --jobs=1
67-
# test-behaviour-connection-cluster:
68-
# image: vaticle-ubuntu-21.04
69-
# type: foreground
70-
# command: |
71-
# python3 -m pip install -U pip
72-
# python3 -m pip install -r requirements_dev.txt
73-
# export ARTIFACT_USERNAME=$REPO_VATICLE_USERNAME
74-
# export ARTIFACT_PASSWORD=$REPO_VATICLE_PASSWORD
75-
# bazel run @vaticle_dependencies//distribution/artifact:create-netrc
76-
# .factory/test-cluster.sh //tests/behaviour/connection/... --test_output=errors --jobs=1
66+
.factory/test-core.sh $(bazel query //tests/behaviour/connection/... except //tests/behaviour/connection/user/...) --test_output=errors --jobs=1
67+
test-behaviour-connection-cluster:
68+
image: vaticle-ubuntu-22.04
69+
type: foreground
70+
command: |
71+
export PATH="$HOME/.local/bin:$PATH"
72+
sudo apt-get update
73+
sudo apt install python3-pip -y
74+
python3 -m pip install -U pip
75+
python3 -m pip install -r requirements_dev.txt
76+
export ARTIFACT_USERNAME=$REPO_VATICLE_USERNAME
77+
export ARTIFACT_PASSWORD=$REPO_VATICLE_PASSWORD
78+
bazel run @vaticle_dependencies//distribution/artifact:create-netrc
79+
.factory/test-cluster.sh //tests/behaviour/connection/... --test_output=errors --jobs=1
7780
test-behaviour-concept-core:
7881
image: vaticle-ubuntu-22.04
7982
type: foreground
@@ -113,22 +116,20 @@ build:
113116
bazel run @vaticle_dependencies//distribution/artifact:create-netrc
114117
.factory/test-core.sh //tests/behaviour/typeql/language/match/... --test_output=errors
115118
.factory/test-core.sh //tests/behaviour/typeql/language/get/... --test_output=errors
116-
# test-behaviour-match-cluster:
117-
# image: vaticle-ubuntu-21.04
118-
# type: foreground
119-
# command: |
120-
# pyenv install 3.7.12
121-
# pyenv global 3.7.12
122-
# python3 -m pip install -U pip
123-
# python3 -m pip install -r requirements_dev.txt
124-
# sudo unlink /usr/bin/python3
125-
# sudo ln -s $(which python3) /usr/bin/python3
126-
# sudo ln -s /usr/share/pyshared/lsb_release.py /opt/pyenv/versions/3.7.12/lib/python3.7/site-packages/lsb_release.py
127-
# export ARTIFACT_USERNAME=$REPO_VATICLE_USERNAME
128-
# export ARTIFACT_PASSWORD=$REPO_VATICLE_PASSWORD
129-
# bazel run @vaticle_dependencies//distribution/artifact:create-netrc
130-
# .factory/test-cluster.sh //tests/behaviour/typeql/language/match/... --test_output=errors
131-
# .factory/test-cluster.sh //tests/behaviour/typeql/language/get/... --test_output=errors
119+
test-behaviour-match-cluster:
120+
image: vaticle-ubuntu-22.04
121+
type: foreground
122+
command: |
123+
export PATH="$HOME/.local/bin:$PATH"
124+
sudo apt-get update
125+
sudo apt install python3-pip -y
126+
python3 -m pip install -U pip
127+
python3 -m pip install -r requirements_dev.txt
128+
export ARTIFACT_USERNAME=$REPO_VATICLE_USERNAME
129+
export ARTIFACT_PASSWORD=$REPO_VATICLE_PASSWORD
130+
bazel run @vaticle_dependencies//distribution/artifact:create-netrc
131+
.factory/test-cluster.sh //tests/behaviour/typeql/language/match/... --test_output=errors
132+
.factory/test-cluster.sh //tests/behaviour/typeql/language/get/... --test_output=errors
132133
test-behaviour-writable-core:
133134
image: vaticle-ubuntu-22.04
134135
type: foreground
@@ -206,10 +207,10 @@ build:
206207
dependencies: [
207208
build,
208209
test-behaviour-connection-core,
209-
# test-behaviour-connection-cluster,
210+
test-behaviour-connection-cluster,
210211
test-behaviour-concept-core, test-behaviour-concept-cluster,
211212
test-behaviour-match-core,
212-
# test-behaviour-match-cluster,
213+
test-behaviour-match-cluster,
213214
test-behaviour-writable-core, test-behaviour-writable-cluster,
214215
test-behaviour-definable-core, test-behaviour-definable-cluster,
215216
test-failover-cluster

dependencies/vaticle/artifacts.bzl

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def vaticle_typedb_artifacts():
2929
artifact_name = "typedb-server-{platform}-{version}.{ext}",
3030
tag_source = deployment["artifact.release"],
3131
commit_source = deployment["artifact.snapshot"],
32-
tag = "2.16.1",
32+
commit = "c36d4deeb6a7f9b53dced92002e57c1df9963f7a",
3333
)
3434

3535
def vaticle_typedb_cluster_artifacts():
@@ -39,5 +39,5 @@ def vaticle_typedb_cluster_artifacts():
3939
artifact_name = "typedb-cluster-all-{platform}-{version}.{ext}",
4040
tag_source = deployment_private["artifact.release"],
4141
commit_source = deployment_private["artifact.snapshot"],
42-
tag = "2.16.1",
42+
commit = "230757ad05e2b1a8cf78a3cb67d90d759de64a19",
4343
)

dependencies/vaticle/repositories.bzl

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,19 @@ def vaticle_dependencies():
2525
git_repository(
2626
name = "vaticle_dependencies",
2727
remote = "https://github.com/vaticle/dependencies",
28-
commit = "0daf20ca5efc141fc8e3f9a767a9118b6eee0980", # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_dependencies
28+
commit = "e0446ffa70cacca89cb1faa2cd6f299c3784d845", # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_dependencies
2929
)
3030

3131
def vaticle_typedb_common():
3232
git_repository(
3333
name = "vaticle_typedb_common",
3434
remote = "https://github.com/vaticle/typedb-common",
35-
tag = "2.16.0" # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_typedb_common
35+
tag = "2.17.0" # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_typedb_common
3636
)
3737

3838
def vaticle_typedb_behaviour():
3939
git_repository(
4040
name = "vaticle_typedb_behaviour",
4141
remote = "https://github.com/vaticle/typedb-behaviour",
42-
commit = "ff4f58b4db2200b907c60b28a2b8ee661449e9c0" # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_typedb_behaviour
42+
commit = "b4cbdd3aaf28428608fc88eae0852425df57fe25" # sync-marker: do not remove this comment, this is used for sync-dependencies by @vaticle_typedb_behaviour
4343
)

requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,6 @@
3535

3636
## Dependencies
3737

38-
typedb-protocol==2.16.1
38+
typedb-protocol==2.17.0
3939
grpcio>=1.43.0,<2
4040
protobuf>=3.15.5,<4

tests/behaviour/background/cluster/environment.py

+19-7
Original file line numberDiff line numberDiff line change
@@ -25,31 +25,43 @@
2525
from tests.behaviour.background import environment_base
2626
from tests.behaviour.context import Context
2727

28-
IGNORE_TAGS = ["ignore", "ignore-client-python", "ignore-typedb-cluster-client-python"]
28+
IGNORE_TAGS = ["ignore", "ignore-client-python", "ignore-typedb-client-python", "ignore-typedb-cluster-client-python"]
2929

3030

3131
def before_all(context: Context):
3232
environment_base.before_all(context)
33-
34-
root_ca_path = os.environ["ROOT_CA"]
35-
credential = TypeDBCredential("admin", "password", root_ca_path)
36-
context.client = TypeDB.cluster_client(addresses=["127.0.0.1:" + context.config.userdata["port"]], credential=credential)
33+
context.credential_root_ca_path = os.environ["ROOT_CA"]
34+
context.setup_context_client_fn = lambda user="admin", password="password": setup_context_client(context, user, password)
3735

3836

3937
def before_scenario(context: Context, scenario):
4038
for tag in IGNORE_TAGS:
4139
if tag in scenario.effective_tags:
4240
scenario.skip("tagged with @" + tag)
4341
return
44-
environment_base.before_scenario(context, scenario)
42+
environment_base.before_scenario(context)
43+
44+
45+
def setup_context_client(context, username, password):
46+
credential = TypeDBCredential(username, password, context.credential_root_ca_path)
47+
context.client = TypeDB.cluster_client(addresses=["127.0.0.1:" + context.config.userdata["port"]], credential=credential)
4548
context.session_options = TypeDBOptions.cluster().set_infer(True)
4649
context.transaction_options = TypeDBOptions.cluster().set_infer(True)
4750

4851

49-
5052
def after_scenario(context: Context, scenario):
5153
environment_base.after_scenario(context, scenario)
5254

55+
# TODO: reset the database through the TypeDB runner once it exists
56+
context.setup_context_client_fn()
57+
for database in context.client.databases().all():
58+
database.delete()
59+
60+
for user in context.client.users().all():
61+
if user.username() != "admin":
62+
context.client.users().delete(user.username())
63+
context.client.close()
64+
5365

5466
def after_all(context: Context):
5567
environment_base.after_all(context)

tests/behaviour/background/core/environment.py

+14-2
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,33 @@
2929

3030
def before_all(context: Context):
3131
environment_base.before_all(context)
32-
context.client = TypeDB.core_client(address="localhost:%d" % int(context.config.userdata["port"]))
32+
context.setup_context_client_fn = lambda user=None, password=None: setup_context_client(context, user, password)
3333

3434

3535
def before_scenario(context: Context, scenario):
3636
for tag in IGNORE_TAGS:
3737
if tag in scenario.effective_tags:
3838
scenario.skip("tagged with @" + tag)
3939
return
40-
environment_base.before_scenario(context, scenario)
40+
environment_base.before_scenario(context)
41+
42+
43+
def setup_context_client(context, username=None, password=None):
44+
if username is not None or password is not None:
45+
raise Exception("Core client does not support authentication")
46+
context.client = TypeDB.core_client(address="localhost:%d" % int(context.config.userdata["port"]))
4147
context.session_options = TypeDBOptions.core().set_infer(True)
4248
context.transaction_options = TypeDBOptions.core().set_infer(True)
4349

50+
4451
def after_scenario(context: Context, scenario):
4552
environment_base.after_scenario(context, scenario)
4653

54+
# TODO: reset the database through the TypeDB runner once it exists
55+
context.setup_context_client_fn()
56+
for database in context.client.databases().all():
57+
database.delete()
58+
context.client.close()
4759

4860
def after_all(context: Context):
4961
environment_base.after_all(context)

tests/behaviour/background/environment_base.py

+9-12
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,16 @@ def before_all(context: Context):
2929
context.THREAD_POOL_SIZE = 32
3030

3131

32-
def before_scenario(context: Context, scenario):
33-
for database in context.client.databases().all():
34-
database.delete()
32+
def before_scenario(context: Context):
33+
# setup context state
3534
context.sessions = []
3635
context.sessions_to_transactions = {}
3736
context.sessions_parallel = []
3837
context.sessions_to_transactions_parallel = {}
3938
context.sessions_parallel_to_transactions_parallel = {}
40-
context.tx = lambda: context.sessions_to_transactions[context.sessions[0]][0]
4139
context.things = {}
40+
# setup context functions
41+
context.tx = lambda: context.sessions_to_transactions[context.sessions[0]][0]
4242
context.get = lambda var: context.things[var]
4343
context.put = lambda var, thing: _put_impl(context, var, thing)
4444
context.get_thing_type = lambda root_label, type_label: _get_thing_type_impl(context, root_label, type_label)
@@ -60,6 +60,8 @@ def _get_thing_type_impl(context: Context, root_label: RootLabel, type_label: st
6060
return context.tx().concepts().get_attribute_type(type_label)
6161
elif root_label == RootLabel.RELATION:
6262
return context.tx().concepts().get_relation_type(type_label)
63+
elif root_label == RootLabel.THING:
64+
return context.tx().concepts().get_root_thing_type()
6365
else:
6466
raise ValueError("Unrecognised value")
6567

@@ -74,14 +76,9 @@ def _clear_answers_impl(context: Context):
7476
def after_scenario(context: Context, scenario):
7577
if scenario.status == Status.skipped:
7678
return
77-
78-
for session in context.sessions:
79-
session.close()
80-
for future_session in context.sessions_parallel:
81-
future_session.result().close()
82-
for database in context.client.databases().all():
83-
database.delete()
79+
if context.client.is_open():
80+
context.client.close()
8481

8582

8683
def after_all(context: Context):
87-
context.client.close()
84+
pass

tests/behaviour/config/parameters.py

+15-3
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@
1818
# specific language governing permissions and limitations
1919
# under the License.
2020
#
21+
from enum import Enum
22+
2123
import parse
2224
from behave import register_type
2325
from behave.model import Table
24-
from enum import Enum
2526
# TODO: We aren't consistently using typed parameters in step implementations - we should be.
2627
from typedb.client import *
2728

@@ -48,6 +49,14 @@ def parse_float(text: str) -> float:
4849
register_type(Float=parse_float)
4950

5051

52+
@parse.with_pattern("[\w_-]+")
53+
def parseWords(text):
54+
return text
55+
56+
57+
register_type(Words=parseWords)
58+
59+
5160
@parse.with_pattern(r"\d\d\d\d-\d\d-\d\d(?: \d\d:\d\d:\d\d)?")
5261
def parse_datetime(text: str) -> datetime:
5362
try:
@@ -62,17 +71,20 @@ def parse_datetime(text: str) -> datetime:
6271
class RootLabel(Enum):
6372
ENTITY = 0,
6473
ATTRIBUTE = 1,
65-
RELATION = 2
74+
RELATION = 2,
75+
THING = 3
6676

6777

68-
@parse.with_pattern(r"entity|attribute|relation")
78+
@parse.with_pattern(r"entity|attribute|relation|thing")
6979
def parse_root_label(text: str) -> RootLabel:
7080
if text == "entity":
7181
return RootLabel.ENTITY
7282
elif text == "attribute":
7383
return RootLabel.ATTRIBUTE
7484
elif text == "relation":
7585
return RootLabel.RELATION
86+
elif text == "thing":
87+
return RootLabel.THING
7688
else:
7789
raise ValueError("Unrecognised root label: " + text)
7890

tests/behaviour/connection/connection_steps.py

+45-1
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,55 @@
2020
#
2121

2222
from behave import *
23+
from typedb.common.exception import TypeDBClientException
2324

2425
from tests.behaviour.context import Context
2526

2627

28+
@step(u'typedb has configuration')
29+
def step_impl(context):
30+
# TODO: implement configuring the TypeDB runner when a python typedb-runner is available
31+
pass
32+
33+
34+
@step(u'typedb starts')
35+
def step_impl(context):
36+
# TODO: start TypeDB via a python typedb-runner once one is available
37+
pass
38+
39+
40+
@step(u'connection opens with default authentication')
41+
def step_impl(context):
42+
context.setup_context_client_fn()
43+
for database in context.client.databases().all():
44+
database.delete()
45+
46+
47+
@step(u'connection opens with authentication: {username:Words}, {password:Words}')
48+
def step_impl(context, username: str, password: str):
49+
context.setup_context_client_fn(username, password)
50+
51+
52+
@step(u'connection opens with authentication: {username:Words}, {password:Words}; throws exception')
53+
def step_impl(context, username: str, password: str):
54+
try:
55+
context.setup_context_client_fn(username, password)
56+
assert False
57+
except TypeDBClientException:
58+
pass
59+
60+
61+
@step(u'connection closes')
62+
def step_impl(context):
63+
context.client.close()
64+
65+
66+
@step(u'typedb stops')
67+
def step_impl(context):
68+
# TODO: stop TypeDB via a python typedb-runner once one is available
69+
pass
70+
71+
2772
@step("connection has been opened")
2873
def step_impl(context: Context):
2974
assert context.client and context.client.is_open()
@@ -32,4 +77,3 @@ def step_impl(context: Context):
3277
@step("connection does not have any database")
3378
def step_impl(context: Context):
3479
assert len(context.client.databases().all()) == 0
35-

0 commit comments

Comments
 (0)