Example #1
0
        public async Task <IActionResult> PutCodeVerifier(string id, CodeVerifier codeVerifier)
        {
            if (id != codeVerifier.RequestId)
            {
                return(BadRequest());
            }

            try
            {
                await _repository.codeVerifierRepository.Update(codeVerifier);
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!await CodeVerifierExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Example #2
0
            public AuthState(string stateUrl)
            {
                var random = new AuthRandom();

                Nonce               = random.GenerateNonce();
                CodeVerifier        = random.GenerateCodeVerifier();
                CodeChallenge       = CodeVerifier.ToSHA256Base64UrlSafe();
                CodeChallengeMethod = "S256";
                State               = JsonSerializer.Serialize <object>(new { s = new { url = stateUrl }, v = CodeVerifier }).ToBase64UrlSafe();
            }
        public void PipelineTest()
        {
            // test analysing
            CodeFile codeFile = Builder.BuildStructure(GetTestInput());

            Assert.IsTrue(!String.IsNullOrWhiteSpace(codeFile.PreAutomatonCode));
            Assert.IsTrue(!String.IsNullOrWhiteSpace(codeFile.PostAutomatonCode));
            Assert.IsTrue(codeFile.Automaton != null);

            Assert.IsTrue(codeFile.Automaton.States.Count == 3);

            Assert.IsTrue(codeFile.Automaton.States["Init"].IsStart &&
                          !codeFile.Automaton.States["Init"].IsEnd &&
                          codeFile.Automaton.States["Init"].Name == "Init" &&
                          !String.IsNullOrWhiteSpace(codeFile.Automaton.States["Init"].EntryCode) &&
                          !String.IsNullOrWhiteSpace(codeFile.Automaton.States["Init"].ExitCode));

            Assert.IsTrue(!codeFile.Automaton.States["UpperChar"].IsStart &&
                          !codeFile.Automaton.States["UpperChar"].IsEnd &&
                          codeFile.Automaton.States["UpperChar"].Name == "UpperChar" &&
                          !String.IsNullOrWhiteSpace(codeFile.Automaton.States["UpperChar"].EntryCode) &&
                          String.IsNullOrWhiteSpace(codeFile.Automaton.States["UpperChar"].ExitCode));

            Assert.IsTrue(!codeFile.Automaton.States["LowerChar"].IsStart &&
                          codeFile.Automaton.States["LowerChar"].IsEnd &&
                          codeFile.Automaton.States["LowerChar"].Name == "LowerChar" &&
                          !String.IsNullOrWhiteSpace(codeFile.Automaton.States["LowerChar"].EntryCode) &&
                          String.IsNullOrWhiteSpace(codeFile.Automaton.States["LowerChar"].ExitCode));

            Assert.IsTrue(codeFile.Automaton.Transitions.Count == 4);

            Assert.IsTrue(codeFile.Automaton.Transitions.Single(trans => trans.SourceState.Name == "Init" && trans.TargetState.Name == "LowerChar") != null);
            Assert.IsTrue(codeFile.Automaton.Transitions.Single(trans => trans.SourceState.Name == "LowerChar" && trans.TargetState.Name == "LowerChar") != null);
            Assert.IsTrue(codeFile.Automaton.Transitions.Single(trans => trans.SourceState.Name == "LowerChar" && trans.TargetState.Name == "UpperChar" && !String.IsNullOrWhiteSpace(trans.EntryCode)) != null);
            Assert.IsTrue(codeFile.Automaton.Transitions.Single(trans => trans.SourceState.Name == "UpperChar" && trans.TargetState.Name == "LowerChar" && !String.IsNullOrWhiteSpace(trans.EntryCode)) != null);

            // test generation
            string csharpCode = Generator.GenerateCode(codeFile);

            //Assert.AreEqual(RemoveWhitespace(csharpCode), RemoveWhitespace(GetTestOutput()));

            // test syntax
            Assert.IsTrue(CodeVerifier.Verify(csharpCode), "The syntax of the generated code is broken.");
        }
Example #4
0
        public async Task <ActionResult <CodeVerifier> > PostCodeVerifier(CodeVerifier codeVerifier)
        {
            try
            {
                await _repository.codeVerifierRepository.Add(codeVerifier);
            }
            catch (DbUpdateException)
            {
                if (await CodeVerifierExists(codeVerifier.RequestId))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("GetCodeVerifier", new { id = codeVerifier.RequestId }, codeVerifier));
        }