blob: 9f525a32a80880489acc9f7a203405ff1e8628b5 [file]
#include "fake_auth_context.h"
#include "gmock.h"
#include "gunit.h"
#include "grpcpp/support/string_ref.h"
using ::testing::ElementsAre;
using ::testing::IsEmpty;
namespace {
TEST(FakeAuthContextTest, PeerIdentityMatches) {
milotic::FakeAuthContext auth_context(true);
auth_context.AddProperty("peer", "peer name");
auth_context.SetPeerIdentityPropertyName("peer");
EXPECT_THAT(auth_context.GetPeerIdentity(), ElementsAre("peer name"));
}
TEST(FakeAuthContextTest, MultiplePropertyValues) {
milotic::FakeAuthContext auth_context(true);
auth_context.AddProperty("test_property", "value1");
auth_context.AddProperty("test_property", "value2");
EXPECT_THAT(auth_context.FindPropertyValues("test_property"),
ElementsAre("value1", "value2"));
}
TEST(FakeAuthContextTest, NoValuesFound) {
milotic::FakeAuthContext auth_context(true);
EXPECT_THAT(auth_context.FindPropertyValues("test_property"), IsEmpty());
}
TEST(FakeAuthContextTest, IsPeerAuthenticated) {
milotic::FakeAuthContext auth_context(true);
EXPECT_TRUE(auth_context.IsPeerAuthenticated());
milotic::FakeAuthContext unauth_context(false);
EXPECT_FALSE(unauth_context.IsPeerAuthenticated());
}
TEST(FakeAuthContextTest, GetPeerIdentityPropertyName) {
milotic::FakeAuthContext auth_context(true);
auth_context.SetPeerIdentityPropertyName("custom_identity");
EXPECT_EQ(auth_context.GetPeerIdentityPropertyName(), "custom_identity");
}
TEST(FakeAuthContextTest, IteratorNotSupported) {
milotic::FakeAuthContext auth_context(true);
EXPECT_DEATH(auth_context.begin(), "Iterator not supported");
EXPECT_DEATH(auth_context.end(), "Iterator not supported");
}
TEST(FakeAuthContextTest, EmptyPropertyDoesNotCrash) {
milotic::FakeAuthContext auth_context(true);
grpc::string_ref empty_ref;
auth_context.AddProperty("empty_property", empty_ref);
EXPECT_THAT(auth_context.FindPropertyValues("empty_property"),
ElementsAre(""));
}
} // namespace