Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
DataCatalog
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
eFlows4HPC WP2
DataCatalog
Commits
cecf7f59
Commit
cecf7f59
authored
3 years ago
by
Christian Boettcher
Browse files
Options
Downloads
Patches
Plain Diff
test secrets with jsondb backend
parent
7ef878e0
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
apiserver/storage/JsonFileStorageAdapter.py
+3
-3
3 additions, 3 deletions
apiserver/storage/JsonFileStorageAdapter.py
tests/storage_tests/test_jsonbackend.py
+53
-1
53 additions, 1 deletion
tests/storage_tests/test_jsonbackend.py
with
56 additions
and
4 deletions
apiserver/storage/JsonFileStorageAdapter.py
+
3
−
3
View file @
cecf7f59
...
...
@@ -74,7 +74,7 @@ class JsonFileStorageAdapter(AbstractLocationDataStorageAdapter):
raise
FileNotFoundError
()
if
not
os
.
path
.
isfile
(
full_path
):
log
.
error
(
"
Requsted object (%s) %s does not exist.
"
,
oid
,
full_path
)
log
.
error
(
"
Requ
e
sted object (%s) %s does not exist.
"
,
oid
,
full_path
)
raise
FileNotFoundError
(
f
"
The requested object (
{
oid
}
)
{
full_path
}
does not exist.
"
)
return
full_path
...
...
@@ -160,7 +160,7 @@ class JsonFileStorageAdapter(AbstractLocationDataStorageAdapter):
try
:
return
secrets
[
key
]
except
KeyError
:
raise
HTTPException
(
404
)
raise
HTTPException
(
404
,
f
"
Secret with key
{
key
}
does not exist for the object
{
n_type
}
/
{
oid
}
"
)
def
delete_secret
(
self
,
n_type
:
LocationDataType
,
oid
:
str
,
key
:
str
,
usr
:
str
):
"""
delete and return the value of the requested secret for the given object
"""
...
...
@@ -168,7 +168,7 @@ class JsonFileStorageAdapter(AbstractLocationDataStorageAdapter):
secrets
=
self
.
__load_secrets
(
secrets_path
)
val
=
secrets
.
pop
(
key
,
None
)
if
not
val
:
raise
HTTPException
(
404
,
"
Secret
does not exist.
"
)
raise
HTTPException
(
404
,
f
"
Secret
with key
{
key
}
does not exist for the object
{
n_type
}
/
{
oid
}
"
)
# TODO log
self
.
__store_secrets
(
secrets_path
,
secrets
)
return
val
This diff is collapsed.
Click to expand it.
tests/storage_tests/test_jsonbackend.py
+
53
−
1
View file @
cecf7f59
...
...
@@ -7,7 +7,7 @@ import os
import
pathlib
import
shutil
import
json
from
fastapi.exceptions
import
HTTPException
class
SomeTests
(
unittest
.
TestCase
):
def
setUp
(
self
):
...
...
@@ -17,6 +17,8 @@ class SomeTests(unittest.TestCase):
parents
=
True
,
exist_ok
=
True
)
self
.
store
=
JsonFileStorageAdapter
(
self
.
test_config
)
self
.
secret_type
=
LocationDataType
.
DATASET
self
.
secret_oid
=
"
secrets-testing-oid
"
def
tearDown
(
self
):
if
os
.
path
.
exists
(
self
.
test_config
.
json_storage_path
):
...
...
@@ -107,3 +109,53 @@ class SomeTests(unittest.TestCase):
self
.
assertFalse
(
verify_oid
(
oid
=
'
random strawberry
'
))
self
.
assertFalse
(
verify_oid
(
oid
=
None
))
self
.
assertFalse
(
verify_oid
(
oid
=
1
))
def
test_secrets_list_empty
(
self
):
self
.
secret_oid
=
self
.
store
.
add_new
(
self
.
secret_type
,
LocationData
(
name
=
"
secrets_test
"
,
url
=
"
secrets_url
"
),
""
)[
0
]
secrets
=
self
.
store
.
list_secrets
(
self
.
secret_type
,
self
.
secret_oid
,
""
)
self
.
assertEqual
(
len
(
secrets
),
0
)
self
.
store
.
delete
(
self
.
secret_type
,
self
.
secret_oid
,
""
)
def
test_secrets_add_get_delete
(
self
):
self
.
secret_oid
=
self
.
store
.
add_new
(
self
.
secret_type
,
LocationData
(
name
=
"
secrets_test
"
,
url
=
"
secrets_url
"
),
""
)[
0
]
key
=
"
secretkey
"
val
=
"
secretvalue
"
val2
=
"
othersecretvalue
"
self
.
store
.
add_update_secret
(
self
.
secret_type
,
self
.
secret_oid
,
key
,
val
,
""
)
secrets
=
self
.
store
.
list_secrets
(
self
.
secret_type
,
self
.
secret_oid
,
""
)
self
.
assertEqual
(
len
(
secrets
),
1
)
get_val
=
self
.
store
.
get_secret
(
self
.
secret_type
,
self
.
secret_oid
,
key
,
""
)
self
.
assertEqual
(
val
,
get_val
)
self
.
store
.
add_update_secret
(
self
.
secret_type
,
self
.
secret_oid
,
key
,
val2
,
""
)
get_val2
=
self
.
store
.
get_secret
(
self
.
secret_type
,
self
.
secret_oid
,
key
,
""
)
self
.
assertEqual
(
val2
,
get_val2
)
self
.
store
.
delete_secret
(
self
.
secret_type
,
self
.
secret_oid
,
key
,
""
)
secrets
=
self
.
store
.
list_secrets
(
self
.
secret_type
,
self
.
secret_oid
,
""
)
self
.
assertEqual
(
len
(
secrets
),
0
)
self
.
store
.
delete
(
self
.
secret_type
,
self
.
secret_oid
,
""
)
def
test_secrets_add_list_multiple
(
self
):
self
.
secret_oid
=
self
.
store
.
add_new
(
self
.
secret_type
,
LocationData
(
name
=
"
secrets_test
"
,
url
=
"
secrets_url
"
),
""
)[
0
]
size
=
10
secret_touples
=
[(
f
'
key_
{
i
}
'
,
f
'
secret_
{
i
}
'
)
for
i
in
range
(
size
)]
for
secret
in
secret_touples
:
self
.
store
.
add_update_secret
(
self
.
secret_type
,
self
.
secret_oid
,
secret
[
0
],
secret
[
1
],
""
)
secrets
=
self
.
store
.
list_secrets
(
self
.
secret_type
,
self
.
secret_oid
,
""
)
self
.
assertEqual
(
len
(
secrets
),
size
)
for
secret
in
secret_touples
:
val
=
self
.
store
.
delete_secret
(
self
.
secret_type
,
self
.
secret_oid
,
secret
[
0
],
""
)
self
.
assertEqual
(
val
,
secret
[
1
])
self
.
store
.
delete
(
self
.
secret_type
,
self
.
secret_oid
,
""
)
def
test_secrets_delete_nonexistent
(
self
):
self
.
secret_oid
=
self
.
store
.
add_new
(
self
.
secret_type
,
LocationData
(
name
=
"
secrets_test
"
,
url
=
"
secrets_url
"
),
""
)[
0
]
self
.
assertRaises
(
HTTPException
,
self
.
store
.
delete_secret
,
self
.
secret_type
,
self
.
secret_oid
,
"
somekey
"
,
""
)
self
.
store
.
delete
(
self
.
secret_type
,
self
.
secret_oid
,
""
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment