Пример #1
0
    public async Task <bool> Validate(DocumentId documentId, CancellationToken token)
    {
        BlockChain?blockChain = (await Get(documentId, token))?.ToBlockChain();

        if (blockChain == null)
        {
            return(false);
        }

        ValidateRequest request = blockChain.GetPrincipleDigests(onlyUnsighed: false).ToValidateRequest();

        return(await _signingClient.Validate(request, token));
    }
Пример #2
0
    public async Task GivenIdentityEntry_WhenSigned_WillVerify()
    {
        const string issuer = "*****@*****.**";

        IdentityClient client     = TestApplication.GetIdentityClient();
        SigningClient  signClient = TestApplication.GetSigningClient();

        var documentId = new DocumentId("identity:test/unit-tests-identity/identity1");

        var query = new QueryParameter()
        {
            Filter    = "test/unit-tests-identity",
            Recursive = false,
        };

        IReadOnlyList <DatalakePathItem> search = (await client.Search(query).ReadNext()).Records;
        bool isInsearch = search.Any(x => x.Name == documentId.Path);

        bool deleted = await client.Delete(documentId);

        (isInsearch == deleted).Should().BeTrue();

        var request = new IdentityEntryRequest
        {
            DirectoryId = (string)documentId,
            Issuer      = issuer
        };

        bool success = await client.Create(request);

        success.Should().BeTrue();

        var signRequest = new SignRequest
        {
            PrincipleDigests = new[]
            {
                new PrincipleDigest
                {
                    PrincipleId = (string)documentId,
                    Digest      = Guid.NewGuid().ToString()
                }
            }
        };

        SignRequestResponse signedJwt = await signClient.Sign(signRequest);

        signedJwt.Should().NotBeNull();
        (signedJwt.Errors == null || signedJwt.Errors.Count == 0).Should().BeTrue();
        signedJwt.PrincipleDigests.Count.Should().Be(1);

        var validateRequest = new ValidateRequest
        {
            PrincipleDigests = new[]
            {
                new PrincipleDigest
                {
                    PrincipleId  = (string)documentId,
                    Digest       = signRequest.PrincipleDigests[0].Digest,
                    JwtSignature = signedJwt.PrincipleDigests.First().JwtSignature,
                }
            }
        };

        bool jwtValidated = await signClient.Validate(validateRequest);

        jwtValidated.Should().BeTrue();

        await client.Delete(documentId);

        search = (await client.Search(query).ReadNext()).Records;
        search.Any(x => x.Name == (string)documentId).Should().BeFalse();
    }