示例#1
0
        private Dictionary <string, string> GetMutatedProofKeyHeaders(
            Dictionary <string, string> original,
            Func <long, Dictionary <string, string> > proofKeyGeneration)
        {
            ProofKeyMutator mutator = Mutators.OfType <ProofKeyMutator>().FirstOrDefault();

            return(mutator == null ? original : mutator.Mutate(original, proofKeyGeneration));
        }
        public void Mutate_SpecifiedAttributes_ExpectedMutation()
        {
            // Arrange
            const bool   mutateCurrent = true;
            const bool   mutateOld     = true;
            const string keyRelation   = null;

            Dictionary <string, string> originalHeaders = CreateDefaultProofKeyHeaders();
            ProofKeyMutator             mutator         = new ProofKeyMutator(mutateCurrent, mutateOld, MutatedWopiTimestampString, keyRelation);

            // Act
            Dictionary <string, string> mutatedHeaders = mutator.Mutate(originalHeaders, proofKeyGeneration: CreateProofKeyHeadersWithMutatedTimestamp);

            // Assert
            Assert.AreEqual(ProofKeyMutator.InvalidBase64String, mutatedHeaders[Constants.Headers.ProofKey]);
            Assert.AreEqual(ProofKeyMutator.InvalidBase64String, mutatedHeaders[Constants.Headers.ProofKeyOld]);
            Assert.AreEqual(MutatedWopiTimestamp, mutatedHeaders[Constants.Headers.WopiTimestamp]);
        }
        public void Mutate_NullAttributes_NoMutation()
        {
            // Arrange
            const bool   mutateCurrent = false;
            const bool   mutateOld     = false;
            const string timestamp     = null;
            const string keyRelation   = null;           /* default synced */
            Dictionary <string, string> originalHeaders = CreateDefaultProofKeyHeaders();
            ProofKeyMutator             mutator         = new ProofKeyMutator(mutateCurrent, mutateOld, timestamp, keyRelation);

            // Act
            Dictionary <string, string> mutatedHeaders = mutator.Mutate(originalHeaders, proofKeyGeneration: CreateProofKeyHeadersWithMutatedTimestamp);

            // Assert
            Assert.AreEqual(CurrentProofKey, mutatedHeaders[Constants.Headers.ProofKey]);
            Assert.AreEqual(OldProofKey, mutatedHeaders[Constants.Headers.ProofKeyOld]);
            Assert.AreEqual(WopiTimestamp, mutatedHeaders[Constants.Headers.WopiTimestamp]);
        }
        public void Mutate_KeyRelationBehind_ExpectedMutation()
        {
            // Arrange
            const bool mutateCurrent = false;
            const bool mutateOld     = false;

            Dictionary <string, string> originalHeaders = CreateDefaultProofKeyHeaders();
            ProofKeyMutator             mutator         = new ProofKeyMutator(
                mutateCurrent,
                mutateOld,
                MutatedWopiTimestampString,
                ProofKeyMutator.KeyRelationType.Behind);

            // Act
            Dictionary <string, string> mutatedHeaders = mutator.Mutate(originalHeaders, proofKeyGeneration: CreateProofKeyHeadersWithMutatedTimestamp);

            // Assert
            Assert.AreEqual(OldProofKey, mutatedHeaders[Constants.Headers.ProofKey]);
            Assert.AreEqual(ProofKeyMutator.InvalidBase64String, mutatedHeaders[Constants.Headers.ProofKeyOld]);
            Assert.AreEqual(MutatedWopiTimestamp, mutatedHeaders[Constants.Headers.WopiTimestamp]);
        }
        public void Mutate_KeyRelationAhead_ExpectedMutation()
        {         // Arrange
            const bool   mutateCurrent        = false;
            const bool   mutateOld            = false;
            const string mutatedWopiTimestamp = null;

            Dictionary <string, string> originalHeaders = CreateDefaultProofKeyHeaders();
            ProofKeyMutator             mutator         = new ProofKeyMutator(
                mutateCurrent,
                mutateOld,
                mutatedWopiTimestamp,
                ProofKeyMutator.KeyRelationType.Ahead);

            // Act
            Dictionary <string, string> mutatedHeaders = mutator.Mutate(originalHeaders);

            // Assert
            Assert.AreEqual(ProofKeyMutator.InvalidBase64String, mutatedHeaders[Constants.Headers.ProofKey]);
            Assert.AreEqual(CurrentProofKey, mutatedHeaders[Constants.Headers.ProofKeyOld]);
            Assert.AreEqual(WopiTimestamp, mutatedHeaders[Constants.Headers.WopiTimestamp]);
        }
        public void Mutate_KeyRelationBehindOverridesSpecifiedMutation_ExpectedMutationRetainsTimestampOverride()
        {
            // Arrange
            const bool mutateCurrent = true;
            const bool mutateOld     = true;

            Dictionary <string, string> originalHeaders = CreateDefaultProofKeyHeaders();
            ProofKeyMutator             mutator         = new ProofKeyMutator(
                mutateCurrent,
                mutateOld,
                MutatedWopiTimestampString,
                ProofKeyMutator.KeyRelationType.Behind);

            // Act
            Dictionary <string, string> mutatedHeaders = mutator.Mutate(originalHeaders);

            // Assert
            Assert.AreEqual(OldProofKey, mutatedHeaders[Constants.Headers.ProofKey]);
            Assert.AreEqual(ProofKeyMutator.InvalidBase64String, mutatedHeaders[Constants.Headers.ProofKeyOld]);
            Assert.AreEqual(MutatedWopiTimestamp, mutatedHeaders[Constants.Headers.WopiTimestamp]);
        }