Пример #1
0
    public void Key_CanPrintAndReset_BySchemeAndIssuer()
    {
        var projectPath = _fixture.CreateProject();
        var project     = Path.Combine(projectPath, "TestProject.csproj");

        var app = new Program(_console);

        app.Run(new[] { "create", "--project", project, "--issuer", "test-issuer", "--scheme", "test-scheme" });
        app.Run(new[] { "create", "--project", project, "--issuer", "test-issuer", "--scheme", "test-scheme-2" });
        app.Run(new[] { "create", "--project", project, "--issuer", "test-issuer-2", "--scheme", "test-scheme" });
        app.Run(new[] { "create", "--project", project, "--issuer", "test-issuer-2", "--scheme", "test-scheme-3" });

        Assert.Contains("New JWT saved", _console.GetOutput());
        _console.ClearOutput();

        app.Run(new[] { "key", "--project", project, "--scheme", "test-scheme", "--issuer", "test-issuer" });
        var printMatches = Regex.Matches(_console.GetOutput(), "Signing Key: '(.*?)'");
        var key          = printMatches.SingleOrDefault().Groups[1].Value;

        _console.ClearOutput();

        app.Run(new[] { "key", "--project", project, "--reset", "--force", "--scheme", "test-scheme", "--issuer", "test-issuer" });
        var resetMatches = Regex.Matches(_console.GetOutput(), "New signing key created: '(.*?)'");
        var resetKey     = resetMatches.SingleOrDefault().Groups[1].Value;

        Assert.NotEqual(key, resetKey);
    }
Пример #2
0
    public void SetSecrets(bool fromCurrentDirectory)
    {
        var secrets = new KeyValuePair <string, string>[]
        {
            new KeyValuePair <string, string>("key1", Guid.NewGuid().ToString()),
            new KeyValuePair <string, string>("Facebook:AppId", Guid.NewGuid().ToString()),
            new KeyValuePair <string, string>(@"key-@\/.~123!#$%^&*())-+==", @"key-@\/.~123!#$%^&*())-+=="),
            new KeyValuePair <string, string>("key2", string.Empty),
            new KeyValuePair <string, string>("-oneDashedKey", "-oneDashedValue"),
            new KeyValuePair <string, string>("--twoDashedKey", "--twoDashedValue")
        };

        var projectPath = _fixture.GetTempSecretProject();
        var dir         = fromCurrentDirectory
            ? projectPath
            : Path.GetTempPath();
        var secretManager = new Program(_console, dir);

        foreach (var secret in secrets)
        {
            var parameters = fromCurrentDirectory ?
                             new string[] { "set", secret.Key, secret.Value, "--verbose" } :
            new string[] { "set", secret.Key, secret.Value, "-p", projectPath, "--verbose" };
            secretManager.RunInternal(parameters);
        }

        foreach (var keyValue in secrets)
        {
            Assert.Contains(
                string.Format(CultureInfo.InvariantCulture, "Successfully saved {0} = {1} to the secret store.", keyValue.Key, keyValue.Value),
                _console.GetOutput());
        }

        _console.ClearOutput();
        var args = fromCurrentDirectory
            ? new string[] { "list", "--verbose" }
            : new string[] { "list", "-p", projectPath, "--verbose" };

        secretManager.RunInternal(args);
        foreach (var keyValue in secrets)
        {
            Assert.Contains(
                string.Format(CultureInfo.InvariantCulture, "{0} = {1}", keyValue.Key, keyValue.Value),
                _console.GetOutput());
        }

        // Remove secrets.
        _console.ClearOutput();
        foreach (var secret in secrets)
        {
            var parameters = fromCurrentDirectory ?
                             new string[] { "remove", secret.Key, "--verbose" } :
            new string[] { "remove", secret.Key, "-p", projectPath, "--verbose" };
            secretManager.RunInternal(parameters);
        }

        // Verify secrets are removed.
        _console.ClearOutput();
        args = fromCurrentDirectory
            ? new string[] { "list", "--verbose" }
            : new string[] { "list", "-p", projectPath, "--verbose" };
        secretManager.RunInternal(args);
        Assert.Contains(Resources.Error_No_Secrets_Found, _console.GetOutput());
    }