コード例 #1
0
ファイル: CliTests.cs プロジェクト: ebekker/keypear
    public async Task Create_Vaults()
    {
        using var cli = new CliTester();
        await cli.InitAsync();

        int ret;

        ret = await cli.InvokeAsync("reg", "--email", "*****@*****.**", "--password", "foobar", "--raw-session");

        Assert.Equal(0, ret);

        var sessionKey = cli.ReadOut();

        Assert.NotEmpty(sessionKey);

        cli.SetEnv("KYPR_SESSION", sessionKey);

        ret = await cli.InvokeAsync("list", "vaults");

        Assert.Equal(0, ret);

        var output = cli.ReadOut();

        Assert.NotEmpty(output);

        var vaults = JsonSerializer.Deserialize <ListVaultsCommand.ListVaultsOutput>(output);

        Assert.Empty(vaults !.Vaults);

        ret += await cli.InvokeAsync("new", "vault", "--label", "v1");

        ret += await cli.InvokeAsync("new", "vault", "--label", "v2");

        ret += await cli.InvokeAsync("new", "vault", "--label", "v3");

        var vaultIds = cli.ReadOut().Trim().Split(Environment.NewLine);

        Assert.Equal(3, vaultIds.Length);

        ret += await cli.InvokeAsync("list", "vaults");

        Assert.Equal(0, ret);

        output = cli.ReadOut();
        vaults = JsonSerializer.Deserialize <ListVaultsCommand.ListVaultsOutput>(output);
        Assert.Equal(3, vaults !.Vaults.Count);

        Assert.True(vaults.Vaults.All(x => vaultIds.Contains(x.Id.ToString())));
        Assert.True(vaultIds.All(x => vaults.Vaults.Any(y => y.Id.ToString() == x)));
    }
コード例 #2
0
ファイル: CliTests.cs プロジェクト: ebekker/keypear
    public async Task Create_TOTP_Record_and_Generate_Code()
    {
        using var cli = new CliTester();
        await cli.InitAsync();

        await cli.InvokeSuccessfullyAsync("reg", "--email", "*****@*****.**", "--password", "foobar", "--raw-session");

        var sessionKey = cli.ReadOut();

        cli.SetEnv("KYPR_SESSION", sessionKey);

        await cli.InvokeSuccessfullyAsync("new", "vault", "--label", "v1");

        _ = cli.ReadOut();

        await cli.InvokeSuccessfullyAsync("new", "rec", "--vault", "v1", "--file", "samples/record-totp1.json");

        var recId = cli.ReadOut().Trim();

        await cli.InvokeSuccessfullyAsync("get", "otp", "--record", recId);

        var otpCode = cli.ReadOut().Trim();

        Assert.NotEmpty(otpCode);
        Assert.Equal(6, otpCode.Length);

        var otpSecret  = "I65VU7K5ZQL7WB4E";
        var otpCodeUrl = $"https://authenticationtest.com/totp/?secret={otpSecret}";

        using var http = new HttpClient();
        var otpJson = await http.GetStringAsync(otpCodeUrl);

        var otpResp = JsonSerializer.Deserialize <AuthTestOtpResponse>(otpJson);

        Assert.Equal(otpResp !.code, otpCode);
    }