InsecureCredentials : Comparator implementation (#28899)

* InsecureCredentials: Update cmp_impl

* Fix tests

* Unused argument
pull/28903/head
Yash Tibrewal 3 years ago committed by GitHub
parent c65a55383a
commit 95c12d88c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      src/core/lib/security/credentials/insecure/insecure_credentials.cc
  2. 22
      test/core/security/credentials_test.cc

@ -38,10 +38,9 @@ class InsecureCredentials final : public grpc_channel_credentials {
}
private:
int cmp_impl(const grpc_channel_credentials* other) const override {
// TODO(yashykt): Check if we can do something better here
return QsortCompare(static_cast<const grpc_channel_credentials*>(this),
other);
int cmp_impl(const grpc_channel_credentials* /* other */) const override {
// All insecure credentials objects should compare equal.
return 0;
}
};

@ -3553,14 +3553,14 @@ TEST(CredentialsTest,
}
TEST(CredentialsTest, TestInsecureCredentialsCompareSuccess) {
auto* insecure_creds_1 = grpc_insecure_credentials_create();
auto* insecure_creds_2 = grpc_insecure_credentials_create();
GPR_ASSERT(insecure_creds_1->cmp(insecure_creds_2) == 0);
auto insecure_creds_1 = grpc_insecure_credentials_create();
auto insecure_creds_2 = grpc_insecure_credentials_create();
ASSERT_EQ(insecure_creds_1->cmp(insecure_creds_2), 0);
grpc_arg arg_1 = grpc_channel_credentials_to_arg(insecure_creds_1);
grpc_channel_args args_1 = {1, &arg_1};
grpc_arg arg_2 = grpc_channel_credentials_to_arg(insecure_creds_2);
grpc_channel_args args_2 = {1, &arg_2};
GPR_ASSERT(grpc_channel_args_compare(&args_1, &args_2) == 0);
EXPECT_EQ(grpc_channel_args_compare(&args_1, &args_2), 0);
grpc_channel_credentials_release(insecure_creds_1);
grpc_channel_credentials_release(insecure_creds_2);
}
@ -3568,15 +3568,21 @@ TEST(CredentialsTest, TestInsecureCredentialsCompareSuccess) {
TEST(CredentialsTest, TestInsecureCredentialsCompareFailure) {
auto* insecure_creds = grpc_insecure_credentials_create();
auto* fake_creds = grpc_fake_transport_security_credentials_create();
GPR_ASSERT(insecure_creds->cmp(fake_creds) != 0);
GPR_ASSERT(fake_creds->cmp(insecure_creds) != 0);
ASSERT_NE(insecure_creds->cmp(fake_creds), 0);
ASSERT_NE(fake_creds->cmp(insecure_creds), 0);
grpc_arg arg_1 = grpc_channel_credentials_to_arg(insecure_creds);
grpc_channel_args args_1 = {1, &arg_1};
grpc_arg arg_2 = grpc_channel_credentials_to_arg(fake_creds);
grpc_channel_args args_2 = {1, &arg_2};
GPR_ASSERT(grpc_channel_args_compare(&args_1, &args_2) != 0);
grpc_channel_credentials_release(insecure_creds);
EXPECT_NE(grpc_channel_args_compare(&args_1, &args_2), 0);
grpc_channel_credentials_release(fake_creds);
grpc_channel_credentials_release(insecure_creds);
}
TEST(CredentialsTest, TestInsecureCredentialsSingletonCreate) {
auto* insecure_creds_1 = grpc_insecure_credentials_create();
auto* insecure_creds_2 = grpc_insecure_credentials_create();
EXPECT_EQ(insecure_creds_1, insecure_creds_2);
}
TEST(CredentialsTest, TestFakeCallCredentialsCompareSuccess) {

Loading…
Cancel
Save