Skip to content
This repository has been archived by the owner on Apr 5, 2023. It is now read-only.

feat: Validate and check Waci profile creation that each scope has output descriptors configured. #586

Merged
merged 1 commit into from
Jan 27, 2022

Conversation

talwinder50
Copy link
Member

closes #581

Signed-off-by: talwinder50 [email protected]

@cla-bot cla-bot bot added the cla-signed label Jan 27, 2022
@talwinder50 talwinder50 changed the title feat: Validate and check Waci profile creation that each scope has output descriptors configured. WIP feat: Validate and check Waci profile creation that each scope has output descriptors configured. Jan 27, 2022
@talwinder50 talwinder50 changed the title WIP feat: Validate and check Waci profile creation that each scope has output descriptors configured. feat: Validate and check Waci profile creation that each scope has output descriptors configured. Jan 27, 2022
@talwinder50 talwinder50 force-pushed the issue-581 branch 2 times, most recently from 0b05a86 to b9e3b49 Compare January 27, 2022 19:56
@@ -46,6 +48,7 @@ type WalletConnect struct {

// txnData contains session data.
type txnData struct {
// Todo rename this to profile ID
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this todo still be here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes the issuerID is now misleading it should be profileID added specifically on the value to be renamed. Didnt mention issue number as it can be done part of any follow up prs.

for _, pCredScope := range profileData.CredentialScopes {
if _, ok := o.cmOutputDescriptor[pCredScope]; !ok {
commhttp.WriteErrorResponseWithLog(rw, http.StatusInternalServerError,
fmt.Sprintf("failed to get output descriptors configured for waci "+
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two things:

  1. This string has no formatting directives, so you can simply use the string without calling fmt.Sprintf
  2. I think this error message isn't specific enough - why couldn't the output descriptors get configured? What exactly went wrong?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has formatting directives now

@@ -646,6 +686,31 @@ func TestCreateProfile(t *testing.T) {

require.Contains(t, resErr.ErrMessage, "create oidc client")
})
t.Run("create profile - failed to output descriptors configured for waci profiles", func(t *testing.T) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You probably mean "failed to configure output descriptors for WACI profiles" instead

@codecov
Copy link

codecov bot commented Jan 27, 2022

Codecov Report

Merging #586 (c01fddb) into main (30ecbb5) will increase coverage by 0.16%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #586      +/-   ##
==========================================
+ Coverage   87.70%   87.86%   +0.16%     
==========================================
  Files          28       28              
  Lines        4106     4119      +13     
==========================================
+ Hits         3601     3619      +18     
+ Misses        299      294       -5     
  Partials      206      206              
Impacted Files Coverage Δ
pkg/profile/issuer/profile.go 90.00% <100.00%> (+0.52%) ⬆️
pkg/restapi/issuer/operation/operations.go 89.98% <100.00%> (+0.53%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 30ecbb5...c01fddb. Read the comment docs.

e.states[issuerID] = state
e.states[profileID] = state

resp, err := bddutil.HTTPDo(http.MethodGet, //nolint: bodyclose
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a false positive for the linter? If so, you can add a small comment next to the nolint to let other developers know. (I've also encountered this false positive, there's an open issue for it)

//nolint: bodyclose // False positive


// validating only status code as the vue page needs javascript support
if resp.StatusCode != http.StatusOK {
// nolint:wrapcheck // ignore
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should replace // ignore with a specific reason of why you need the nolint


defer bddutil.CloseResponseBody(resp.Body)

// validating only status code as the vue page needs javascript support
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what vue pages/Javascript have to do with this. Can you explain?

(It might just be me who isn't familiar with how this works, so let me know)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the existing code i only changed variable name and this endpoint gets automatically redirects to vue page thats why its written here that we are only testing status code

func (e *Steps) createProfileWithWACI(id, name, issuerURL, supportedVCContexts, linkedWallet, oidcProvider string) error { //nolint:lll
err := e.createProfile(id, name, issuerURL, supportedVCContexts, "false", "false", oidcProvider, linkedWallet, true)
// id, name, issuerURL, supportedVCContexts, credScope, issuerID, linkedWallet, oidcProvider string
func (e *Steps) createProfileWithWACI(id, name, issuerURL, supportedVCContexts, credScopes, issuerID, linkedWallet, oidcProvider string) error { //nolint:lll
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With how many arguments are in this function, it makes sense to create a custom struct type to hold them all instead. This will also help to resolve the lll linter complaint.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be done as part of #593


func (e *Steps) createProfileWithWACI(id, name, issuerURL, supportedVCContexts, linkedWallet, oidcProvider string) error { //nolint:lll
err := e.createProfile(id, name, issuerURL, supportedVCContexts, "false", "false", oidcProvider, linkedWallet, true)
// id, name, issuerURL, supportedVCContexts, credScope, issuerID, linkedWallet, oidcProvider string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leftover commented out param list from when you were editing this?

@talwinder50 talwinder50 force-pushed the issue-581 branch 2 times, most recently from cfd16a4 to fe0ac37 Compare January 27, 2022 20:28
@@ -125,6 +125,12 @@ func validateProfileRequest(pr *ProfileData) error {
return fmt.Errorf("supported vc contexts mandatory")
}

if pr.SupportsWACI {
if pr.IssuerID == "" {
return fmt.Errorf("issuer id mandatory for waci profiles")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we combine this into one line (if pr.SupportsWACI && pr.IssuerID == "") ?

@@ -16,6 +16,8 @@ import (
)

// ProfileDataRequest req for profile creation.
// Issuer ID identifies who is the issuer of the credential manifests being issued.
// CMStyle represents an entity styles object as defined in credential manifest spec.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add these field level specific comments at field level than at struct level ?

if profileData.SupportsWACI {
for _, pCredScope := range profileData.CredentialScopes {
if _, ok := o.cmOutputDescriptor[pCredScope]; !ok {
commhttp.WriteErrorResponseWithLog(rw, http.StatusInternalServerError,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be BadRequest error code than ServerError.

for _, pCredScope := range profileData.CredentialScopes {
if _, ok := o.cmOutputDescriptor[pCredScope]; !ok {
commhttp.WriteErrorResponseWithLog(rw, http.StatusInternalServerError,
fmt.Sprint("failed to find the allowed cred scope in credential manifest output descriptor "+
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its better to pass the missing scope in the response message as to be more explicit about failed scope to the caller.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One other thing I'd like to suggest...

Is this scenario something that can happen due to an incorrect configuration by the user? If so - you can add something here to make it more explicit how it happens and give them a hint as to how to fix it. (Something like are the scopes configured?)

However, if that configuration is already validated and this error is only here because of the ok check (and so this scenario is essentially impossible) then you can ignore what I wrote above.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By impossible, I mean that there's no way a user can end up in this situation without modifying the code somehow.

@talwinder50 talwinder50 force-pushed the issue-581 branch 2 times, most recently from 15775b0 to 0f0529f Compare January 27, 2022 20:50
…tput descriptors configured.

closes trustbloc#581

Signed-off-by: talwinder50 <[email protected]>
@talwinder50 talwinder50 merged commit de984ef into trustbloc:main Jan 27, 2022
@@ -125,6 +125,10 @@ func validateProfileRequest(pr *ProfileData) error {
return fmt.Errorf("supported vc contexts mandatory")
}

if pr.SupportsWACI && pr.IssuerID == "" {
return fmt.Errorf("issuer id mandatory for waci profiles")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it is not mandatory, you can assign UUID if not set. Refer my comments from original PR.

@@ -46,6 +48,7 @@ type WalletConnect struct {

// txnData contains session data.
type txnData struct {
// Todo #580 rename IssuerID to ProfileID
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why renaming issuerID to profileID???
#580 doesn't mention any of this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#580 (comment) @sudeshrshetty This was my reason,

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Validate and check Waci profile creation that each scope has output descriptors configured.
5 participants