public void Create_Should_UseVirgilService_AccordingToAppToken()
        {
            var contextVirgil = ProtocolContext.Create(
                appToken: "AT.SOMETOKEN",
                servicePublicKey: this.servicePublicKey,
                appSecretKey: this.clientSecretKey);

            Assert.Equal(this.virgilServiceUrl, ((HttpClientBase)contextVirgil.Client).BaseUri.AbsoluteUri);
        }
        public void Create_Should_RaiseException_IfTokenDoesnHaveCorrectPrefix()
        {
            var ex = Record.Exception(() =>
            {
                ProtocolContext.Create(
                    appToken: "OO.SOMETOKEN",
                    servicePublicKey: this.servicePublicKey,
                    appSecretKey: this.clientSecretKey);
            });

            Assert.IsType <ServiceClientException>(ex);
        }
        [Fact] // HTC-10
        public void Create_Should_RaiseExceptionIfUpdateTokenVersionIsIncorect()
        {
            // if update token version != current version + 1, then raise exception.
            var ex = Record.Exception(() =>
            {
                ProtocolContext.Create(
                    appToken: this.appToken,
                    servicePublicKey: this.servicePublicKey,
                    appSecretKey: this.clientSecretKey,
                    updateToken: this.updateTokenV3);
            });

            Assert.IsType <WrongVersionException>(ex);
        }
        [Fact] // HTC-8
        public void Create_Should_SetKeysVersionToCurrentVersion()
        {
            // if there is no updateToken, then
            // 1)current version is set up from keys' version
            // 2)context has only one pair of keys
            var contextWithUpdateToken = ProtocolContext.Create(
                appToken: this.appToken,
                servicePublicKey: this.servicePublicKey2,
                appSecretKey: this.clientSecretKey2);

            Assert.Equal <uint>(2, contextWithUpdateToken.CurrentVersion);
            Assert.True(contextWithUpdateToken.PheClients.Count == 1);
            Assert.Equal <uint>(2, contextWithUpdateToken.PheClients.Keys.First <uint>());
        }
        [Fact] // HTC-9
        public void Create_Should_RotateKeysIfUpdateTokenIsBigger()
        {
            // if update token version == current version + 1, then
            // 1)new keys are calculated
            // 2)current vesion == updateToken version
            // 3)context keeps keys for previous and current versions
            var contextWithUpdateToken = ProtocolContext.Create(
                appToken: this.appToken,
                servicePublicKey: this.servicePublicKey,
                appSecretKey: this.clientSecretKey,
                updateToken: this.updateTokenV2);

            Assert.Equal <uint>(2, contextWithUpdateToken.CurrentVersion);
            Assert.Equal(2, contextWithUpdateToken.PheClients.Count);
            Assert.Equal <uint>(2, contextWithUpdateToken.PheClients.Keys.Last <uint>());
        }
Ejemplo n.º 6
0
        public async Task Should_EnrollNewRecord_When_PasswordSpecified()
        {
            var context = ProtocolContext.Create(
                appId: "e60e6d91b0e3480b816f306337e96aaa",
                accessToken: "-rTsFFkAOGf6am4bEF_aAdoHt2kOGy78",
                serverPublicKey: "PK.1.BJ2+TUK/WVTfuYjgKj0KOVH4nKUqdBihqhH/EN1fyggwATu4gzGMC0P35jBDZnSTEFdm2zmC4qndyI5MKBvFjX8=",
                clientSecretKey: "SK.1.W7FVp+LhG/ton7P+wKu0ndIPECY5+mTzX7iWaW9+sXA="
                );

            var protocol = new Protocol(context);

            var record = await protocol.EnrollAsync("passw0rd");

            await Task.Delay(2000);

            var verifyResult = await protocol.VerifyAsync(record, "passw0rd");

            var context1 = ProtocolContext.Create(
                appId: "e60e6d91b0e3480b816f306337e96aaa",
                accessToken: "-rTsFFkAOGf6am4bEF_aAdoHt2kOGy78",
                serverPublicKey: "PK.1.BJ2+TUK/WVTfuYjgKj0KOVH4nKUqdBihqhH/EN1fyggwATu4gzGMC0P35jBDZnSTEFdm2zmC4qndyI5MKBvFjX8=",
                clientSecretKey: "SK.1.W7FVp+LhG/ton7P+wKu0ndIPECY5+mTzX7iWaW9+sXA=",
                updateTokens: new[] {
                "UT.2.MEQEIGw7O3Hm/9rSUBrShEFKiQQk8yi39TnGS7dpUP9/8aQiBCBhp5NxCylYeCpJq/hjK2SuTiA9Pl8zD8BZUDau6B72Ag=="
            }
                );

            var protocol1 = new Protocol(context1);

            var record1 = protocol1.Update(record);

            await Task.Delay(2000);

            var verifyResult1 = await protocol1.VerifyAsync(record1, "passw0rd");

            Assert.True(verifyResult.IsSuccess);
        }