public void GetCertificate_ReturnsCertificateData() { // Arrange var clientFake = A.Fake <IVaultClient>(); var httpClientFake = A.Fake <IVaultHttpClient>(); A.CallTo(() => clientFake.ServiceClient).Returns(httpClientFake); A.CallTo(() => httpClientFake.Post <PkiIssue, PkiIssueResult>("v1/pki/issue/roleName", A <PkiIssue> ._)) .Returns(new PkiIssueResult { Data = new PkiData { Certificate = Encoding.UTF8.GetBytes("TestCertificate"), PrivateKey = Encoding.UTF8.GetBytes("TestPrivateKey") } }); var store = new VaultCertificateStore(clientFake, "roleName", "commonName"); // Act var result = store.GetCertificate(); // Assert result.Certificate.Should().BeEquivalentTo(Encoding.UTF8.GetBytes("TestCertificate")); result.PrivateKey.Should().BeEquivalentTo(Encoding.UTF8.GetBytes("TestPrivateKey")); A.CallTo(() => httpClientFake.Post <PkiIssue, PkiIssueResult>("v1/pki/issue/roleName", A <PkiIssue> .That.Matches(r => r.CommonName == "commonName"))); }
public void GetCertificate_ServiceClientThrowsException_ReturnsNull() { // Arrange var clientFake = A.Fake <IVaultClient>(); A.CallTo(() => clientFake.ServiceClient).Throws <WebException>(); var store = new VaultCertificateStore(clientFake, "roleName", "commonName"); // Act var result = store.GetCertificate(); // Assert result.Should().BeNull(); }
public void GetCertificate_PostReturnsNull_ReturnsNull() { // Arrange var clientFake = A.Fake <IVaultClient>(); var httpClientFake = A.Fake <IVaultHttpClient>(); A.CallTo(() => clientFake.ServiceClient).Returns(httpClientFake); A.CallTo(() => httpClientFake.Post <PkiIssue, PkiIssueResult>("v1/pki/issue/roleName", A <PkiIssue> ._)) .Returns(null); var store = new VaultCertificateStore(clientFake, "roleName", "commonName"); // Act var result = store.GetCertificate(); // Assert result.Should().BeNull(); A.CallTo(() => httpClientFake.Post <PkiIssue, PkiIssueResult>("v1/pki/issue/roleName", A <PkiIssue> .That.Matches(r => r.CommonName == "commonName"))); }