Ejemplo n.º 1
0
 public VerificationTest(MockHttpClientFixture mockHttpClientFixture) : base(mockHttpClientFixture)
 {
     _verificationService = new VerificationService("KEYSUPERSECRET");
     profileListOptions   = new VerifyProfileListOptions
     {
         Filter = "Test"
     };
     profileOptions = new VerifyProfileOptions
     {
         DefaultTimeoutSecs = 300,
         MessagingEnabled   = true,
         MessagingTemplate  = "Hello this is a test {code}",
         Name       = "Test Profile",
         RcsEnabled = false
     };
     verifyOptions = new VerifyOptions
     {
         TimeoutSecs     = 300,
         PhoneNumber     = "+13100000010",
         VerifyProfileId = Guid.NewGuid(),
         Type            = "sms",
     };
     codeOptions = new VerifyCodeOptions
     {
         Code = "2222"
     };
 }
        private static object RunVerifyAndReturnExitCode(VerifyOptions opts)
        {
            if (!configurationHelper.ReadConfig())
            {
                return(false);
            }

            var twin = iotDeviceHelper.QueryDeviceTwin(opts.DevEui, configurationHelper).Result;

            if (twin != null)
            {
                Console.WriteLine();
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine($"DevEUI: {opts.DevEui}");
                Console.WriteLine(TwinToString(twin));
                Console.ResetColor();

                return(iotDeviceHelper.VerifyDeviceTwin(opts.DevEui, opts.NetId, twin, configurationHelper));
            }
            else
            {
                StatusConsole.WriteLine(MessageType.Error, $"Could not get data for device {opts.DevEui}.");
                return(false);
            }
        }
Ejemplo n.º 3
0
        private static object RunVerifyAndReturnExitCode(VerifyOptions opts)
        {
            if (!configurationHelper.ReadConfig())
            {
                return(false);
            }

            Console.WriteLine($"Querying DevEUI: {opts.DevEui} ...\n");

            var twinData = iotDeviceHelper.QueryTwinSingle(opts.DevEui, configurationHelper).Result;

            if (twinData != null)
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine(twinData.ToString());
                Console.ResetColor();
                Console.WriteLine();

                Console.WriteLine($"Verifying Device: {opts.DevEui} ...\n");
                return(iotDeviceHelper.VerifyTwinSingle(opts.DevEui, twinData));
            }
            else
            {
                Console.WriteLine($"Could not get data for device {opts.DevEui}.");
                return(false);
            }
        }
Ejemplo n.º 4
0
        private static async Task <int> RunVerifyAndReturnExitCode(VerifyOptions opts)
        {
            SpeechApi.Initialize(
                new SpeechApi.Builder()
                .SetDeveloperKey(opts.DeveloperKey)
                .SetApplicationKey(opts.ApplicationKey)
                .SetApplicationSource("Dynamic.Speech.Samples")
                .SetLogger(Logger)
                .Build()
                );

            if (string.IsNullOrEmpty(opts.Path) || !Directory.Exists(opts.Path))
            {
                Logger.LogError("No Verification Directory Found for ClientId: {0}", opts.ClientId);
                return(1);
            }

            string[] verifyFiles = Directory.GetFiles(opts.Path, "*.wav");
            if (verifyFiles == null || verifyFiles.Length == 0)
            {
                Logger.LogError("No Verification Files Found for ClientId Folder: {0}", opts.ClientId);
                return(1);
            }

            await PerformVerify(opts, verifyFiles);

            return(0);
        }
Ejemplo n.º 5
0
        public async Task RunVerification()
        {
            VerifyProfileOptions profileOptions = new VerifyProfileOptions
            {
                DefaultTimeoutSecs = 300,
                MessagingEnabled   = true,
                MessagingTemplate  = "Hello this is a test {code}",
                Name       = "Test Profile",
                RcsEnabled = false
            };

            Console.WriteLine($"Creating profile: {profileOptions.Name}");
            var profile = await verifyService.CreateVerificationProfileAsync(profileOptions);

            Console.WriteLine($"Profile Created. Id: {profile.Id.Value}");
            VerifyOptions verifyOptions = new VerifyOptions
            {
                TimeoutSecs     = 300,
                PhoneNumber     = "+13100000010",
                VerifyProfileId = profile.Id.Value,
                Type            = "sms",
            };

            Console.WriteLine($"Creating verification");
            var verification = await verifyService.CreateVerificationAsync(verifyOptions);

            Console.WriteLine($"Verification created successfully: {verification.Id} with status {verification.Status}");

            Console.WriteLine($"Checking verification status current status: {verification.Status}");
            var getStatus = await verifyService.GetVerificationAsync(verification.Id.ToString());

            Console.WriteLine($"Verification retrieved previous status: {verification.Status}, current status: {getStatus.Status}");
        }
Ejemplo n.º 6
0
        private static int RunVerifyRulesCommand(VerifyOptions opts)
        {
#if DEBUG
            Logger.Setup(true, opts.Verbose, opts.Quiet);
#else
            Logger.Setup(opts.Debug, opts.Verbose, opts.Quiet);
#endif
            var analyzer = new Analyzer(AsaHelpers.GetPlatform(), opts.AnalysisFile);
            if (analyzer.VerifyRules())
            {
                return((int)ASA_ERROR.NONE);
            }

            return((int)ASA_ERROR.INVALID_RULES);
        }
        static async Task <int> Verify(VerifyOptions options)
        {
            try
            {
                var userId = await UserRegistrationQueryService.GetUserId(options.Email);

                await UserRegistrationCommandService.EmailVerified(userId, options.Email);
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.Message);
            }

            return(0);
        }
Ejemplo n.º 8
0
        private static async Task PerformVerify(VerifyOptions opts, string[] verifyFiles)
        {
            var verifier = new SpeechVerifier();

            verifier.ClientId = opts.ClientId;

            if (!string.IsNullOrEmpty(opts.InteractionId))
            {
                verifier.InteractionId = opts.InteractionId;
            }

            if (!string.IsNullOrEmpty(opts.InteractionTag))
            {
                verifier.InteractionTag = opts.InteractionTag;
            }

            try
            {
                if (await verifier.StartAsync())
                {
                    foreach (var file in verifyFiles)
                    {
                        await verifier.PostAsync(file);

                        Logger.LogInfo("Speech-Extracted: {0}", verifier.SpeechExtracted);
                        Logger.LogInfo("Verify-Score: {0}", verifier.VerifyScore);
                    }

                    var result = await verifier.SummarizeAsync();

                    Logger.LogInfo("Has-Enough-Speech: {0}", verifier.HasEnoughSpeech);
                    Logger.LogInfo("Has-Result: {0}", verifier.HasResult);
                    Logger.LogInfo("Result: {0}", result);
                    Logger.LogInfo("Is-Authorized: {0}", verifier.IsAuthorized);
                    Logger.LogInfo("Is-Verified: {0}", verifier.IsVerified);
                    Logger.LogInfo("Speech-Extracted: {0}", verifier.SpeechExtracted);
                    Logger.LogInfo("Verify-Score: {0}", verifier.VerifyScore);
                }
            }
            catch (Exception ex)
            {
                Logger.LogError(ex);
                if (verifier.IsSessionOpen)
                {
                    await verifier.CancelAsync("Exception Occurred");
                }
            }
        }
Ejemplo n.º 9
0
        public bool VerifyLocalizableItems(VerifyOptions options)
        {
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            var  verificator = new LocalizableItemsVerificator(options.SourceDirectory, cultures);
            bool result      = verificator.VerificateAllFiles();

            Console.WriteLine("End");
            stopwatch.Stop();
            TimeSpan ts = stopwatch.Elapsed;

            Console.WriteLine(string.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10));

            return(result);
        }
Ejemplo n.º 10
0
        private static int RunVerifyRulesCommand(VerifyOptions opts)
        {
#if DEBUG
            Logger.Setup(true, opts.Verbose, opts.Quiet);
#else
            Logger.Setup(opts.Debug, opts.Verbose, opts.Quiet);
#endif
            var analyzer   = new Analyzer(AsaHelpers.GetPlatform(), opts.AnalysisFile);
            var violations = analyzer.VerifyRules();
            Analyzer.PrintViolations(violations);
            if (violations.Any())
            {
                Log.Error("Encountered {0} issues with rules at {1}", violations.Count, opts.AnalysisFile ?? "Embedded");
                return((int)ASA_ERROR.INVALID_RULES);
            }
            Log.Information("Rules successfully verified. ✅");
            return((int)ASA_ERROR.NONE);
        }
Ejemplo n.º 11
0
        public CommandLineParserTests(ITestOutputHelper output)
        {
            _output = output;

            _parser = CommandLineParser.Create(
                new ServiceCollection(),
                startServer: (options, invocationContext) =>
            {
                _startOptions = options;
            },
                demo: (options, console, context, startOptions) =>
            {
                _demoOptions = options;
                return(Task.CompletedTask);
            },
                tryGithub: (options, c) =>
            {
                _tryGitHubOptions = options;
                return(Task.CompletedTask);
            },
                pack: (options, console) =>
            {
                _packOptions = options;
                return(Task.CompletedTask);
            },
                install: (options, console) =>
            {
                _installOptions       = options;
                _installPackageSource = options.AddSource;
                return(Task.CompletedTask);
            },
                verify: (options, console, startupOptions) =>
            {
                _verifyOptions = options;
                return(Task.FromResult(0));
            },
                telemetry: new FakeTelemetry(),
                publish: (options, console, startupOptions) =>
            {
                _publishOptions = options;
                return(Task.FromResult(0));
            },
                firstTimeUseNoticeSentinel: new NopFirstTimeUseNoticeSentinel());
        }
        private static async Task <bool> RunVerifyAndReturnExitCode(VerifyOptions opts)
        {
            if (!configurationHelper.ReadConfig())
            {
                return(false);
            }

            var twin = await iotDeviceHelper.QueryDeviceTwin(opts.DevEui, configurationHelper);

            if (twin != null)
            {
                StatusConsole.WriteTwin(opts.DevEui, twin);
                return(iotDeviceHelper.VerifyDeviceTwin(opts.DevEui, opts.NetId, twin, configurationHelper, true));
            }
            else
            {
                StatusConsole.WriteLogLine(MessageType.Error, $"Could not get data for device {opts.DevEui}.");
                return(false);
            }
        }
Ejemplo n.º 13
0
        public CommandLineParserTests(ITestOutputHelper output)
        {
            _output = output;

            _parser = CommandLineParser.Create(
                startServer: (options, invocationContext) =>
            {
                _start_options = options;
            },
                demo: (options, console, context, startOptions) =>
            {
                _demoOptions = options;
                return(Task.CompletedTask);
            },
                tryGithub: (options, c) =>
            {
                _tryGitHubOptions = options;
                return(Task.CompletedTask);
            },
                pack: (options, console) =>
            {
                _packOptions = options;
                return(Task.CompletedTask);
            },
                install: (options, console) =>
            {
                _installOptions        = options;
                _install_packageSource = options.AddSource;
                return(Task.CompletedTask);
            },
                verify: (options, console, startupOptions) =>
            {
                _verifyOptions = options;
                return(Task.FromResult(1));
            },
                jupyter: (options, console, startServer, context) =>
            {
                _jupyter_Options = options;
                return(Task.FromResult(1));
            });
        }
Ejemplo n.º 14
0
 public VerifyService(VerifyOptions options)
 {
     Options = options;
 }
Ejemplo n.º 15
0
        internal static void DoVerify(VerifyOptions options)
        {
            DicConsole.DebugWriteLine("Verify command", "--debug={0}", options.Debug);
            DicConsole.DebugWriteLine("Verify command", "--verbose={0}", options.Verbose);
            DicConsole.DebugWriteLine("Verify command", "--input={0}", options.InputFile);
            DicConsole.DebugWriteLine("Verify command", "--verify-disc={0}", options.VerifyDisc);
            DicConsole.DebugWriteLine("Verify command", "--verify-sectors={0}", options.VerifySectors);

            FiltersList filtersList = new FiltersList();
            IFilter     inputFilter = filtersList.GetFilter(options.InputFile);

            if (inputFilter == null)
            {
                DicConsole.ErrorWriteLine("Cannot open specified file.");
                return;
            }

            IMediaImage inputFormat = ImageFormat.Detect(inputFilter);

            if (inputFormat == null)
            {
                DicConsole.ErrorWriteLine("Unable to recognize image format, not verifying");
                return;
            }

            inputFormat.Open(inputFilter);
            Core.Statistics.AddMediaFormat(inputFormat.Format);
            Core.Statistics.AddMedia(inputFormat.Info.MediaType, false);
            Core.Statistics.AddFilter(inputFilter.Name);

            bool?correctDisc    = null;
            long totalSectors   = 0;
            long errorSectors   = 0;
            long correctSectors = 0;
            long unknownSectors = 0;

            if (options.VerifyDisc)
            {
                DateTime startCheck      = DateTime.UtcNow;
                bool?    discCheckStatus = inputFormat.VerifyMediaImage();
                DateTime endCheck        = DateTime.UtcNow;

                TimeSpan checkTime = endCheck - startCheck;

                switch (discCheckStatus)
                {
                case true:
                    DicConsole.WriteLine("Disc image checksums are correct");
                    break;

                case false:
                    DicConsole.WriteLine("Disc image checksums are incorrect");
                    break;

                case null:
                    DicConsole.WriteLine("Disc image does not contain checksums");
                    break;
                }

                correctDisc = discCheckStatus;
                DicConsole.VerboseWriteLine("Checking disc image checksums took {0} seconds", checkTime.TotalSeconds);
            }

            if (options.VerifySectors)
            {
                bool formatHasTracks;
                try
                {
                    List <Track> inputTracks = inputFormat.Tracks;
                    formatHasTracks = inputTracks.Count > 0;
                }
                catch { formatHasTracks = false; }

                DateTime     startCheck;
                DateTime     endCheck;
                List <ulong> failingLbas = new List <ulong>();
                List <ulong> unknownLbas = new List <ulong>();

                if (formatHasTracks)
                {
                    List <Track> inputTracks      = inputFormat.Tracks;
                    ulong        currentSectorAll = 0;

                    startCheck = DateTime.UtcNow;
                    foreach (Track currentTrack in inputTracks)
                    {
                        ulong remainingSectors = currentTrack.TrackEndSector - currentTrack.TrackStartSector;
                        ulong currentSector    = 0;

                        while (remainingSectors > 0)
                        {
                            DicConsole.Write("\rChecking sector {0} of {1}, on track {2}", currentSectorAll,
                                             inputFormat.Info.Sectors, currentTrack.TrackSequence);

                            List <ulong> tempfailingLbas;
                            List <ulong> tempunknownLbas;

                            if (remainingSectors < 512)
                            {
                                inputFormat.VerifySectors(currentSector, (uint)remainingSectors,
                                                          currentTrack.TrackSequence, out tempfailingLbas,
                                                          out tempunknownLbas);
                            }
                            else
                            {
                                inputFormat.VerifySectors(currentSector, 512, currentTrack.TrackSequence,
                                                          out tempfailingLbas, out tempunknownLbas);
                            }

                            failingLbas.AddRange(tempfailingLbas);

                            unknownLbas.AddRange(tempunknownLbas);

                            if (remainingSectors < 512)
                            {
                                currentSector    += remainingSectors;
                                currentSectorAll += remainingSectors;
                                remainingSectors  = 0;
                            }
                            else
                            {
                                currentSector    += 512;
                                currentSectorAll += 512;
                                remainingSectors -= 512;
                            }
                        }
                    }

                    endCheck = DateTime.UtcNow;
                }
                else
                {
                    ulong remainingSectors = inputFormat.Info.Sectors;
                    ulong currentSector    = 0;

                    startCheck = DateTime.UtcNow;
                    while (remainingSectors > 0)
                    {
                        DicConsole.Write("\rChecking sector {0} of {1}", currentSector, inputFormat.Info.Sectors);

                        List <ulong> tempfailingLbas;
                        List <ulong> tempunknownLbas;

                        if (remainingSectors < 512)
                        {
                            inputFormat.VerifySectors(currentSector, (uint)remainingSectors,
                                                      out tempfailingLbas, out tempunknownLbas);
                        }
                        else
                        {
                            inputFormat.VerifySectors(currentSector, 512, out tempfailingLbas, out tempunknownLbas);
                        }

                        failingLbas.AddRange(tempfailingLbas);

                        unknownLbas.AddRange(tempunknownLbas);

                        if (remainingSectors < 512)
                        {
                            currentSector   += remainingSectors;
                            remainingSectors = 0;
                        }
                        else
                        {
                            currentSector    += 512;
                            remainingSectors -= 512;
                        }
                    }

                    endCheck = DateTime.UtcNow;
                }

                TimeSpan checkTime = endCheck - startCheck;

                DicConsole.Write("\r" + new string(' ', System.Console.WindowWidth - 1) + "\r");

                if (unknownSectors > 0)
                {
                    DicConsole.WriteLine("There is at least one sector that does not contain a checksum");
                }
                if (errorSectors > 0)
                {
                    DicConsole.WriteLine("There is at least one sector with incorrect checksum or errors");
                }
                if (unknownSectors == 0 && errorSectors == 0)
                {
                    DicConsole.WriteLine("All sector checksums are correct");
                }

                DicConsole.VerboseWriteLine("Checking sector checksums took {0} seconds", checkTime.TotalSeconds);

                if (options.Verbose)
                {
                    DicConsole.VerboseWriteLine("LBAs with error:");
                    if (failingLbas.Count == (int)inputFormat.Info.Sectors)
                    {
                        DicConsole.VerboseWriteLine("\tall sectors.");
                    }
                    else
                    {
                        foreach (ulong t in failingLbas)
                        {
                            DicConsole.VerboseWriteLine("\t{0}", t);
                        }
                    }

                    DicConsole.WriteLine("LBAs without checksum:");
                    if (unknownLbas.Count == (int)inputFormat.Info.Sectors)
                    {
                        DicConsole.VerboseWriteLine("\tall sectors.");
                    }
                    else
                    {
                        foreach (ulong t in unknownLbas)
                        {
                            DicConsole.VerboseWriteLine("\t{0}", t);
                        }
                    }
                }

                DicConsole.WriteLine("Total sectors........... {0}", inputFormat.Info.Sectors);
                DicConsole.WriteLine("Total errors............ {0}", failingLbas.Count);
                DicConsole.WriteLine("Total unknowns.......... {0}", unknownLbas.Count);
                DicConsole.WriteLine("Total errors+unknowns... {0}", failingLbas.Count + unknownLbas.Count);

                totalSectors   = (long)inputFormat.Info.Sectors;
                errorSectors   = failingLbas.Count;
                unknownSectors = unknownLbas.Count;
                correctSectors = totalSectors - errorSectors - unknownSectors;
            }

            Core.Statistics.AddCommand("verify");
            Core.Statistics.AddVerify(correctDisc, correctSectors, errorSectors, unknownSectors, totalSectors);
        }
        protected VerifyResult VerifyFlags(string[] Args, out ActionFlags Flags, VerifyOptions Options)
        {
            //Command syntex ensured, because method is called after VerifyFilePath Method
            if (Args.Length == 2 || Args[0][0] != '-')
            {
                Flags = ActionFlags.Names | ActionFlags.Count | ActionFlags.Sheets;
                return(VerifyResult.Success);
            }

            Flags = ActionFlags.None;

            if ((Options & VerifyOptions.ForbidRepeatingArgs) > 0 && Args[0].Length > 6)
            {
                return(VerifyResult.InvalidArguments);
            }

            //Flag collection depending on VerifyOptions arg
            for (int i = 1; i < Args[0].Length; i++)
            {
                switch (Args[0][i])
                {
                case '-': return(VerifyResult.InvalidArguments);

                case 'c':
                    if (!ContainsFlag(Flags, ActionFlags.Count))
                    {
                        Flags = Flags | ActionFlags.Count;
                        break;
                    }
                    else
                    if (ContainsFlag(Options, VerifyOptions.ForbidRepeatingArgs))
                    {
                        return(VerifyResult.InvalidArguments);
                    }
                    break;

                case 'n':
                    if (!ContainsFlag(Flags, ActionFlags.Names))
                    {
                        Flags = Flags | ActionFlags.Names;
                        break;
                    }
                    else
                    if (ContainsFlag(Options, VerifyOptions.ForbidRepeatingArgs))
                    {
                        return(VerifyResult.InvalidArguments);
                    }
                    break;

                case 's':
                    if (!ContainsFlag(Flags, ActionFlags.Sheets))
                    {
                        Flags = Flags | ActionFlags.Sheets;
                        break;
                    }
                    else
                    if (ContainsFlag(Options, VerifyOptions.ForbidRepeatingArgs))
                    {
                        return(VerifyResult.InvalidArguments);
                    }
                    break;

                case 'k':
                    if (!ContainsFlag(Flags, ActionFlags.Keys))
                    {
                        Flags = Flags | ActionFlags.Keys;
                        break;
                    }
                    else
                    if (ContainsFlag(Options, VerifyOptions.ForbidRepeatingArgs))
                    {
                        return(VerifyResult.InvalidArguments);
                    }
                    break;

                case 'u':
                    if (!ContainsFlag(Flags, ActionFlags.Unrestrict))
                    {
                        Flags = Flags | ActionFlags.Unrestrict;
                        break;
                    }
                    else
                    if (ContainsFlag(Options, VerifyOptions.ForbidRepeatingArgs))
                    {
                        return(VerifyResult.InvalidArguments);
                    }
                    break;

                default:
                    if (ContainsFlag(Options, VerifyOptions.ForbidExtraChars))
                    {
                        return(VerifyResult.InvalidArguments);
                    }
                    break;
                }
            }

            if (Flags == ActionFlags.Keys ||
                Flags == ActionFlags.Unrestrict ||
                Flags == (ActionFlags.Unrestrict | ActionFlags.Keys))
            {
                AddDefaultFlags(ref Flags);
            }

            return(VerifyResult.Success);
        }
 static bool ContainsFlag(VerifyOptions obj, VerifyOptions prototype)
 {
     return((obj & prototype) > 0);
 }