Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
ocm-bdd-2-qa
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Mike Sell
ocm-bdd-2-qa
Commits
dfa9adfe
Commit
dfa9adfe
authored
1 year ago
by
Mike Sell
Browse files
Options
Downloads
Patches
Plain Diff
Refactored init.py
parent
eb84dd77
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
features/steps/helper.py
+63
-1
63 additions, 1 deletion
features/steps/helper.py
features/steps/init.py
+7
-51
7 additions, 51 deletions
features/steps/init.py
with
70 additions
and
52 deletions
features/steps/helper.py
+
63
−
1
View file @
dfa9adfe
import
secrets
import
secrets
import
string
import
string
import
requests
import
json
def
generate_random_string
(
length
):
def
generate_random_string
(
length
):
"""
Generate a secure random alphanumeric string of given length.
"""
"""
Generate a secure random alphanumeric string of given length.
"""
alphabet
=
string
.
ascii_letters
+
string
.
digits
# Include both letters and numbers
alphabet
=
string
.
ascii_letters
+
string
.
digits
# Include both letters and numbers
return
''
.
join
(
secrets
.
choice
(
alphabet
)
for
_
in
range
(
length
))
return
''
.
join
(
secrets
.
choice
(
alphabet
)
for
_
in
range
(
length
))
\ No newline at end of file
def
register_endorser_did
(
url_base
,
payload
=
{},
header
=
{}):
endorser_url
=
url_base
+
'
/register-endorser-did
'
requests
.
post
(
endorser_url
,
headers
=
header
,
data
=
payload
)
def
create_issuer_tennant
(
url_base
,
payload
=
json
.
dumps
({
"
label
"
:
"
issuer
"
}),
headers
=
{
'
Content-Type
'
:
'
application/json
'
}
):
url
=
url_base
+
"
/create-tenant
"
return
requests
.
post
(
url
,
headers
=
headers
,
data
=
payload
)
def
register_issuer_did
(
url_base
,
issuer_id
,
seed
=
None
,
payload
=
None
,
headers
=
{
'
Content-Type
'
:
'
application/json
'
}
):
if
seed
is
None
:
seed
=
generate_random_string
(
15
)
\
+
generate_random_string
(
1
)
\
+
generate_random_string
(
1
)
\
+
generate_random_string
(
15
)
if
payload
is
None
:
payload
=
json
.
dumps
({
"
seed
"
:
(
seed
),
"
services
"
:
[
{
"
id
"
:
"
#endpoint
"
,
"
type
"
:
"
endpoint
"
,
"
serviceEndpoint
"
:
"
https://bar.example.com
"
},
{
"
id
"
:
"
#didcomm-messaging
"
,
"
type
"
:
"
didcomm-messaging
"
,
"
serviceEndpoint
"
:
"
https://bar.example.com
"
},
{
"
id
"
:
"
#did-communication
"
,
"
type
"
:
"
did-communication
"
,
"
serviceEndpoint
"
:
"
https://bar.example.com
"
},
{
"
id
"
:
"
#DIDComm
"
,
"
type
"
:
"
DIDComm
"
,
"
serviceEndpoint
"
:
"
https://bar.example.com
"
}
]
})
url
=
url_base
+
'
/v1/dids?tenantId=
'
+
issuer_id
return
requests
.
post
(
url
,
headers
=
headers
,
data
=
payload
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
features/steps/init.py
+
7
−
51
View file @
dfa9adfe
from
behave
import
*
from
behave
import
*
import
requests
import
requests
import
json
import
json
from
helper
import
generate_random_string
from
helper
import
generate_random_string
,
register_endorser_did
,
create_issuer_tennant
,
register_issuer_did
@given
(
u
'
I can connect to OCM Engine
'
)
@given
(
u
'
I can connect to OCM Engine
'
)
...
@@ -22,20 +22,11 @@ def step_init(context):
...
@@ -22,20 +22,11 @@ def step_init(context):
# context.dev_tools_base_URL_2 = localhost + "4110"
# context.dev_tools_base_URL_2 = localhost + "4110"
# Step 1: Register Endorser DID
# Register Endorser DID
empty_payload
=
{}
register_endorser_did
(
context
.
dev_tools_base_URL
)
empty_header
=
{}
endorser_url
=
context
.
dev_tools_base_URL
+
'
/register-endorser-did
'
requests
.
post
(
endorser_url
,
headers
=
empty_header
,
data
=
empty_payload
)
# Create 'issuer' tenant
# Create 'issuer' tenant
payload
=
json
.
dumps
({
"
label
"
:
"
issuer
"
})
create_issuer_tenant_request
=
create_issuer_tennant
(
context
.
dev_tools_base_URL
)
headers
=
{
'
Content-Type
'
:
'
application/json
'
}
url
=
context
.
dev_tools_base_URL
+
"
/create-tenant
"
create_issuer_tenant_request
=
requests
.
post
(
url
,
headers
=
headers
,
data
=
payload
)
assert
create_issuer_tenant_request
.
status_code
==
201
assert
create_issuer_tenant_request
.
status_code
==
201
context
.
issuer_id
=
create_issuer_tenant_request
.
json
()[
'
id
'
]
context
.
issuer_id
=
create_issuer_tenant_request
.
json
()[
'
id
'
]
...
@@ -44,43 +35,8 @@ def step_init(context):
...
@@ -44,43 +35,8 @@ def step_init(context):
@given
(
u
'
I register a DID for
\'
issuer
\'
'
)
@given
(
u
'
I register a DID for
\'
issuer
\'
'
)
def
step_register_issuer_did
(
context
):
def
step_register_issuer_did
(
context
):
register_did_response
=
register_issuer_did
(
context
.
did_manager_base_URL
,
issuer_id
=
context
.
issuer_id
)
print
(
context
.
issuer_id
)
register_did_url
=
context
.
did_manager_base_URL
+
'
/v1/dids?tenantId=
'
+
context
.
issuer_id
print
(
register_did_response
.
json
())
register_did_payload
=
json
.
dumps
({
"
seed
"
:
(
generate_random_string
(
15
)
+
generate_random_string
(
1
)
+
generate_random_string
(
1
)
+
generate_random_string
(
15
)),
"
services
"
:
[
{
"
id
"
:
"
#endpoint
"
,
"
type
"
:
"
endpoint
"
,
"
serviceEndpoint
"
:
"
https://bar.example.com
"
},
{
"
id
"
:
"
#didcomm-messaging
"
,
"
type
"
:
"
didcomm-messaging
"
,
"
serviceEndpoint
"
:
"
https://bar.example.com
"
},
{
"
id
"
:
"
#did-communication
"
,
"
type
"
:
"
did-communication
"
,
"
serviceEndpoint
"
:
"
https://bar.example.com
"
},
{
"
id
"
:
"
#DIDComm
"
,
"
type
"
:
"
DIDComm
"
,
"
serviceEndpoint
"
:
"
https://bar.example.com
"
}
]
})
register_did_headers
=
{
'
Content-Type
'
:
'
application/json
'
}
register_did_response
=
requests
.
post
(
register_did_url
,
headers
=
register_did_headers
,
data
=
register_did_payload
)
assert
register_did_response
.
status_code
==
201
assert
register_did_response
.
status_code
==
201
context
.
issuer_did
=
register_did_response
.
json
()[
"
data
"
][
0
]
context
.
issuer_did
=
register_did_response
.
json
()[
"
data
"
][
0
]
\ 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