예제 #1
0
        private async Task ProtocolWithUpdateToken_Should_VerifyUpdatedRecordForService(ServiceTestData serviceTestData)
        {
            // you can verify updated record if context has updateToken with equal version
            var context = this.InitContext(
                serviceTestData.AppToken,
                serviceTestData.ServicePublicKey2,
                serviceTestData.ClientSecretKey2,
                serviceTestData.ServiceSubdomain);

            var contextWithUpdateToken = this.InitContext(
                serviceTestData.AppToken,
                serviceTestData.ServicePublicKey2,
                serviceTestData.ClientSecretKey2,
                serviceTestData.ServiceSubdomain);

            contextWithUpdateToken.UpdatePheClients(serviceTestData.UpdateTokenV3);

            var protocol     = new Protocol(context);
            var enrollResult = await protocol.EnrollAccountAsync(this.myPassword);

            Assert.Equal <uint>(2, DatabaseRecord.Parser.ParseFrom(enrollResult.Record).Version);

            var recordUpdater   = new RecordUpdater(serviceTestData.UpdateTokenV3);
            var updatedRecBytes = recordUpdater.Update(enrollResult.Record);

            Assert.Equal <uint>(3, DatabaseRecord.Parser.ParseFrom(updatedRecBytes).Version);
            var protocolWithUpdateToken = new Protocol(contextWithUpdateToken);

            var result = await protocol.VerifyPasswordAsync(this.myPassword, enrollResult.Record);

            var result2 = await protocolWithUpdateToken.VerifyPasswordAsync(this.myPassword, updatedRecBytes);

            Assert.Equal(enrollResult.Key, result.Key);
            Assert.Equal(enrollResult.Key, result2.Key);
        }
예제 #2
0
        private async Task Updater_Should_RaiseWrongVersionExceptionIfRecordHasTheSameVersionAsUpdaterForService(ServiceTestData serviceTestData)
        {
            // you will get exception if record version == updater version
            var context = this.InitContext(
                serviceTestData.AppToken,
                serviceTestData.ServicePublicKey2,
                serviceTestData.ClientSecretKey2,
                serviceTestData.ServiceSubdomain);

            context.UpdatePheClients(serviceTestData.UpdateTokenV3);

            var protocol     = new Protocol(context);
            var enrollResult = await protocol.EnrollAccountAsync(this.myPassword);

            Assert.Equal <uint>(3, DatabaseRecord.Parser.ParseFrom(enrollResult.Record).Version);

            var recordUpdater = new RecordUpdater(serviceTestData.UpdateTokenV3);

            var ex = Record.Exception(() =>
            {
                recordUpdater.Update(enrollResult.Record);
            });

            Assert.IsType <WrongVersionException>(ex);
        }
예제 #3
0
        private async Task Updater_Should_RaiseWrongVersionExceptionIfRecordHasWrongVersionForService(ServiceTestData serviceTestData)
        {
            // you will get exception if record version != (updater version - 1)
            var context = this.InitContext(
                serviceTestData.AppToken,
                serviceTestData.ServicePublicKey2,
                serviceTestData.ClientSecretKey2,
                serviceTestData.ServiceSubdomain);

            context.UpdatePheClients(serviceTestData.UpdateTokenV3);

            var protocol     = new Protocol(context);
            var enrollResult = await protocol.EnrollAccountAsync(this.myPassword);

            var databaseRec = DatabaseRecord.Parser.ParseFrom(enrollResult.Record);

            databaseRec.Version = 1;

            var recordUpdater = new RecordUpdater(serviceTestData.UpdateTokenV3);
            var ex            = Record.Exception(() =>
            {
                recordUpdater.Update(databaseRec.ToByteArray());
            });

            Assert.IsType <WrongVersionException>(ex);

            var ex2 = await Record.ExceptionAsync(async() =>
            {
                await protocol.VerifyPasswordAsync(this.myPassword, databaseRec.ToByteArray());
            });

            Assert.IsType <WrongVersionException>(ex2);
        }