This repository has been archived by the owner on Mar 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add new legacy http header to handle legacy requests. Cover with unit tests - Encode invitation Recipient key to base58 - Change embedded verification to referenced while creating verification methods - Add legacy file into doc package to convert DIDdoc to raw doc. Cover with unit test - Add handling DID id's where did method is not specified - Add JSONBytes and ParseConnection methods to use them while handling connection data - Change AckMsgType content to proper one - Add method to convert array of did-keys to base58 keys - Enable saving decryption key while handling envelope at connection-request state - Add new InvitationRecipientKeys into connection.Record model - Refactor requestMsgRecord, handleInboundRequest and prepareConnectionSignature methods and their unit-tests - Save Recipient keys while handling connection request - Use SaveDID instead SaveDIDByResolving Signed-off-by: Abdulbois <abdulbois.tursunov@avast.com>
- Loading branch information
Showing
18 changed files
with
760 additions
and
157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/* | ||
Copyright Avast Software. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package legacyconnection | ||
|
||
import ( | ||
_ "embed" | ||
"encoding/json" | ||
"testing" | ||
|
||
"github.com/btcsuite/btcutil/base58" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/hyperledger/aries-framework-go/pkg/doc/did" | ||
) | ||
|
||
//nolint:gochecknoglobals | ||
var ( | ||
//go:embed testdata/valid_conn_data.jsonld | ||
validConnectionData string | ||
) | ||
|
||
// nolint:lll | ||
func TestJSONConversion(t *testing.T) { | ||
|
||
con, err := parseLegacyJSONBytes([]byte(validConnectionData)) | ||
require.NoError(t, err) | ||
require.NotEmpty(t, con) | ||
|
||
require.Equal(t, con.DID, "did:example:21tDAKCERh95uGgKbJNHYp") | ||
require.Equal(t, con.DIDDoc.ID, "did:example:21tDAKCERh95uGgKbJNHYp") | ||
require.Contains(t, con.DIDDoc.Context, "https://w3id.org/did/v0.11") | ||
require.Equal(t, con.DIDDoc.AlsoKnownAs[0], "did:example:123") | ||
require.Equal(t, con.DIDDoc.VerificationMethod[0].Type, "Secp256k1VerificationKey2018") | ||
require.Equal(t, base58.Encode(con.DIDDoc.VerificationMethod[0].Value), "H3C2AVvLMv6gmMNam3uVAjZpfkcJCwDwnZn6z3wXmqPV") | ||
require.Equal(t, con.DIDDoc.Authentication[0].VerificationMethod.Type, "Secp256k1VerificationKey2018") | ||
require.Equal(t, base58.Encode(con.DIDDoc.Authentication[0].VerificationMethod.Value), "H3C2AVvLMv6gmMNam3uVAjZpfkcJCwDwnZn6z3wXmqPV") | ||
require.Equal(t, con.DIDDoc.Service[0].Type, "IndyAgent") | ||
uri, err := con.DIDDoc.Service[0].ServiceEndpoint.URI() | ||
require.NoError(t, err) | ||
require.Contains(t, uri, "https://agent.example.com/") | ||
require.Equal(t, con.DIDDoc.Service[0].RecipientKeys, []string{"did:example:123456789abcdefghi#key2"}) | ||
require.Equal(t, con.DIDDoc.Service[0].RoutingKeys, []string{"did:example:123456789abcdefghi#key2"}) | ||
|
||
conBytes, err := con.toLegacyJSONBytes() | ||
require.NoError(t, err) | ||
require.NotEmpty(t, conBytes) | ||
|
||
rawString := string(conBytes) | ||
|
||
require.Contains(t, rawString, "\"DID\":\"did:example:21tDAKCERh95uGgKbJNHYp\"") | ||
require.Contains(t, rawString, "\"@context\":\"https://w3id.org/did/v1\"") | ||
require.Contains(t, rawString, "\"controller\":\"did:example:123456789abcdefghi\",\"id\":\"did:example:123456789abcdefghi#keys-1\",\"publicKeyBase58\":\"H3C2AVvLMv6gmMNam3uVAjZpfkcJCwDwnZn6z3wXmqPV\",\"type\":\"Secp256k1VerificationKey2018\"") | ||
require.Contains(t, rawString, "\"authentication\":[{\"publicKey\":\"did:example:123456789abcdefghi#keys-1\",\"type\":\"Secp256k1VerificationKey2018\"},{\"publicKey\":\"did:example:123456789abcdefghs#key3\",\"type\":\"RsaVerificationKey2018\"}]") | ||
require.Contains(t, rawString, "\"service\":[{\"id\":\"did:example:123456789abcdefghi#did-communication\",\"priority\":0,\"recipientKeys\":[\"did:example:123456789abcdefghi#key2\"],\"routingKeys\":[\"did:example:123456789abcdefghi#key2\"],\"serviceEndpoint\":\"https://agent.example.com/\",\"type\":\"IndyAgent\"}]") | ||
} | ||
|
||
func TestToLegacyJSONBytes(t *testing.T) { | ||
con := &Connection{ | ||
DID: "did:example:21tDAKCERh95uGgKbJNHYp", | ||
} | ||
|
||
// Empty DIDDoc data | ||
legacyDoc, err := con.toLegacyJSONBytes() | ||
require.ErrorContains(t, err, "DIDDoc field cannot be empty") | ||
require.Empty(t, legacyDoc) | ||
|
||
// Success | ||
|
||
con.DIDDoc = &did.Doc{ | ||
Context: "https://w3id.org/did/v0.11", | ||
ID: "did:example:21tDAKCERh95uGgKbJNHYp", | ||
} | ||
legacyDoc, err = con.toLegacyJSONBytes() | ||
|
||
require.NoError(t, err) | ||
require.NotEmpty(t, legacyDoc) | ||
require.Contains(t, string(legacyDoc), "\"DID\":\"did:example:21tDAKCERh95uGgKbJNHYp\"") | ||
require.Contains(t, string(legacyDoc), "\"@context\":\"https://w3id.org/did/v1\"") | ||
} | ||
|
||
func TestParseJSONBytes(t *testing.T) { | ||
// Nil payload | ||
conRaw, err := parseLegacyJSONBytes(nil) | ||
require.ErrorContains(t, err, "JSON umarshalling of connection data bytes failed") | ||
require.Empty(t, conRaw) | ||
|
||
// Empty payload | ||
conRaw, err = parseLegacyJSONBytes([]byte{}) | ||
require.ErrorContains(t, err, "JSON umarshalling of connection data bytes failed") | ||
require.Empty(t, conRaw) | ||
|
||
// Empty DIDDoc | ||
docBytes, err := json.Marshal(Connection{ | ||
DID: "did:example:21tDAKCERh95uGgKbJNHYp", | ||
}) | ||
require.NoError(t, err) | ||
require.NotEmpty(t, docBytes) | ||
|
||
conRaw, err = parseLegacyJSONBytes(docBytes) | ||
require.ErrorContains(t, err, "connection DIDDoc field is missed") | ||
require.Empty(t, conRaw) | ||
|
||
// Success | ||
con, err := parseLegacyJSONBytes([]byte(validConnectionData)) | ||
require.NoError(t, err) | ||
require.NotEmpty(t, con) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.