Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix: Deactivated DIDs are not allowed to update. #354

Merged
merged 1 commit into from
Apr 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion tests/e2e/ssi_tests/e2e_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ def deactivate_did():

print("2. PASS: Mike creates a DID for himself, but the controller list is empty. Mike attempts to deactivate it \n")

# Register Alice's DID
# Register Mike's DID
kp_mike = generate_key_pair()
signers = []
did_doc_string = generate_did_document(kp_mike)
Expand All @@ -518,6 +518,36 @@ def deactivate_did():
deactivate_tx_cmd = form_did_deactivate_tx_multisig(did_doc_mike, signers, DEFAULT_BLOCKCHAIN_ACCOUNT_NAME)
run_blockchain_command(deactivate_tx_cmd, f"Deactivation of Mike's DID with Id: {did_doc_mike}")

print("3. FAIL: Mike creates a DID for himself, but the controller list is empty. Mike deactivates it and then attempts to updates it. \n")

kp_mike = generate_key_pair()
signers = []
did_doc_string = generate_did_document(kp_mike)
did_doc_string["controller"] = []
did_doc_mike = did_doc_string["id"]
did_doc_mike_vm = did_doc_string["verificationMethod"][0]
signPair_mike = {
"kp": kp_mike,
"verificationMethodId": did_doc_mike_vm["id"],
"signing_algo": "ed25519"
}
signers.append(signPair_mike)
create_tx_cmd = form_did_create_tx_multisig(did_doc_string, signers, DEFAULT_BLOCKCHAIN_ACCOUNT_NAME)
run_blockchain_command(create_tx_cmd, f"Registering of Mike's DID with Id: {did_doc_mike}")

# Deactivate DID
signers = []
signers.append(signPair_mike)
deactivate_tx_cmd = form_did_deactivate_tx_multisig(did_doc_mike, signers, DEFAULT_BLOCKCHAIN_ACCOUNT_NAME)
run_blockchain_command(deactivate_tx_cmd, f"Deactivation of Mike's DID with Id: {did_doc_mike}")

# Attempt to update deactivated DID
signers = []
signers.append(signPair_mike)
did_doc_string["context"] = ["hii"]
update_tx_cmd = form_did_update_tx_multisig(did_doc_string, signers, DEFAULT_BLOCKCHAIN_ACCOUNT_NAME)
run_blockchain_command(update_tx_cmd, f"Bob (non-controller) attempts to update Org DID with Id: {did_doc_org}", True)

print("--- Test Completed ---\n")

def schema_test():
Expand Down
5 changes: 5 additions & 0 deletions x/ssi/keeper/msg_server_update_did.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ func (k msgServer) UpdateDID(goCtx context.Context, msg *types.MsgUpdateDID) (*t
}
existingDidDocument := existingDidDocumentState.DidDocument

// Check if the DID Document is already deactivated
if existingDidDocumentState.DidDocumentMetadata.Deactivated {
return nil, sdkerrors.Wrapf(types.ErrDidDocDeactivated, "cannot update didDocument %v as it is deactivated", existingDidDocument.Id)
}

// Check if the incoming DID Document has any changes. If not, throw an error.
if reflect.DeepEqual(existingDidDocument, msgDidDocument) {
return nil, sdkerrors.Wrap(types.ErrInvalidDidDoc, "incoming DID Document does not have any changes")
Expand Down