Skip to content

Commit

Permalink
auth context api change for string_ref
Browse files Browse the repository at this point in the history
  • Loading branch information
yang-g committed Aug 25, 2015
1 parent 9f8c100 commit d090fe1
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 53 deletions.
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8945,16 +8945,16 @@ $(BINDIR)/$(CONFIG)/auth_property_iterator_test: protobuf_dep_error

else

$(BINDIR)/$(CONFIG)/auth_property_iterator_test: $(PROTOBUF_DEP) $(AUTH_PROPERTY_ITERATOR_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a
$(BINDIR)/$(CONFIG)/auth_property_iterator_test: $(PROTOBUF_DEP) $(AUTH_PROPERTY_ITERATOR_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a
$(E) "[LD] Linking $@"
$(Q) mkdir -p `dirname $@`
$(Q) $(LDXX) $(LDFLAGS) $(AUTH_PROPERTY_ITERATOR_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/auth_property_iterator_test
$(Q) $(LDXX) $(LDFLAGS) $(AUTH_PROPERTY_ITERATOR_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/auth_property_iterator_test

endif

endif

$(OBJDIR)/$(CONFIG)/test/cpp/common/auth_property_iterator_test.o: $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a
$(OBJDIR)/$(CONFIG)/test/cpp/common/auth_property_iterator_test.o: $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a
deps_auth_property_iterator_test: $(AUTH_PROPERTY_ITERATOR_TEST_OBJS:.o=.dep)

ifneq ($(NO_SECURE),true)
Expand Down Expand Up @@ -10155,16 +10155,16 @@ $(BINDIR)/$(CONFIG)/secure_auth_context_test: protobuf_dep_error

else

$(BINDIR)/$(CONFIG)/secure_auth_context_test: $(PROTOBUF_DEP) $(SECURE_AUTH_CONTEXT_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a
$(BINDIR)/$(CONFIG)/secure_auth_context_test: $(PROTOBUF_DEP) $(SECURE_AUTH_CONTEXT_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a
$(E) "[LD] Linking $@"
$(Q) mkdir -p `dirname $@`
$(Q) $(LDXX) $(LDFLAGS) $(SECURE_AUTH_CONTEXT_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/secure_auth_context_test
$(Q) $(LDXX) $(LDFLAGS) $(SECURE_AUTH_CONTEXT_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/secure_auth_context_test

endif

endif

$(OBJDIR)/$(CONFIG)/test/cpp/common/secure_auth_context_test.o: $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a
$(OBJDIR)/$(CONFIG)/test/cpp/common/secure_auth_context_test.o: $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a
deps_secure_auth_context_test: $(SECURE_AUTH_CONTEXT_TEST_OBJS:.o=.dep)

ifneq ($(NO_SECURE),true)
Expand Down
6 changes: 6 additions & 0 deletions build.json
Original file line number Diff line number Diff line change
Expand Up @@ -2020,8 +2020,11 @@
"test/cpp/common/auth_property_iterator_test.cc"
],
"deps": [
"grpc++_test_util",
"grpc_test_util",
"grpc++",
"grpc",
"gpr_test_util",
"gpr"
]
},
Expand Down Expand Up @@ -2572,8 +2575,11 @@
"test/cpp/common/secure_auth_context_test.cc"
],
"deps": [
"grpc++_test_util",
"grpc_test_util",
"grpc++",
"grpc",
"gpr_test_util",
"gpr"
]
},
Expand Down
7 changes: 4 additions & 3 deletions include/grpc++/support/auth_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include <vector>

#include <grpc++/support/config.h>
#include <grpc++/support/string_ref.h>

struct grpc_auth_context;
struct grpc_auth_property;
Expand All @@ -46,7 +47,7 @@ struct grpc_auth_property_iterator;
namespace grpc {
class SecureAuthContext;

typedef std::pair<grpc::string, grpc::string> AuthProperty;
typedef std::pair<grpc::string_ref, grpc::string_ref> AuthProperty;

class AuthPropertyIterator
: public std::iterator<std::input_iterator_tag, const AuthProperty> {
Expand Down Expand Up @@ -78,11 +79,11 @@ class AuthContext {

// A peer identity, in general is one or more properties (in which case they
// have the same name).
virtual std::vector<grpc::string> GetPeerIdentity() const = 0;
virtual std::vector<grpc::string_ref> GetPeerIdentity() const = 0;
virtual grpc::string GetPeerIdentityPropertyName() const = 0;

// Returns all the property values with the given name.
virtual std::vector<grpc::string> FindPropertyValues(
virtual std::vector<grpc::string_ref> FindPropertyValues(
const grpc::string& name) const = 0;

// Iteration over all the properties.
Expand Down
6 changes: 3 additions & 3 deletions src/cpp/common/auth_property_iterator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ bool AuthPropertyIterator::operator!=(const AuthPropertyIterator& rhs) const {
}

const AuthProperty AuthPropertyIterator::operator*() {
return std::make_pair<grpc::string, grpc::string>(
grpc::string(property_->name),
grpc::string(property_->value, property_->value_length));
return std::pair<grpc::string_ref, grpc::string_ref>(
property_->name,
grpc::string_ref(property_->value, property_->value_length));
}

} // namespace grpc
17 changes: 9 additions & 8 deletions src/cpp/common/secure_auth_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,16 @@ SecureAuthContext::SecureAuthContext(grpc_auth_context* ctx) : ctx_(ctx) {}

SecureAuthContext::~SecureAuthContext() { grpc_auth_context_release(ctx_); }

std::vector<grpc::string> SecureAuthContext::GetPeerIdentity() const {
std::vector<grpc::string_ref> SecureAuthContext::GetPeerIdentity() const {
if (!ctx_) {
return std::vector<grpc::string>();
return std::vector<grpc::string_ref>();
}
grpc_auth_property_iterator iter = grpc_auth_context_peer_identity(ctx_);
std::vector<grpc::string> identity;
std::vector<grpc::string_ref> identity;
const grpc_auth_property* property = nullptr;
while ((property = grpc_auth_property_iterator_next(&iter))) {
identity.push_back(grpc::string(property->value, property->value_length));
identity.push_back(
grpc::string_ref(property->value, property->value_length));
}
return identity;
}
Expand All @@ -62,17 +63,17 @@ grpc::string SecureAuthContext::GetPeerIdentityPropertyName() const {
return name == nullptr ? "" : name;
}

std::vector<grpc::string> SecureAuthContext::FindPropertyValues(
std::vector<grpc::string_ref> SecureAuthContext::FindPropertyValues(
const grpc::string& name) const {
if (!ctx_) {
return std::vector<grpc::string>();
return std::vector<grpc::string_ref>();
}
grpc_auth_property_iterator iter =
grpc_auth_context_find_properties_by_name(ctx_, name.c_str());
const grpc_auth_property* property = nullptr;
std::vector<grpc::string> values;
std::vector<grpc::string_ref> values;
while ((property = grpc_auth_property_iterator_next(&iter))) {
values.push_back(grpc::string(property->value, property->value_length));
values.push_back(grpc::string_ref(property->value, property->value_length));
}
return values;
}
Expand Down
6 changes: 3 additions & 3 deletions src/cpp/common/secure_auth_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ class SecureAuthContext GRPC_FINAL : public AuthContext {

~SecureAuthContext() GRPC_OVERRIDE;

std::vector<grpc::string> GetPeerIdentity() const GRPC_OVERRIDE;
std::vector<grpc::string_ref> GetPeerIdentity() const GRPC_OVERRIDE;

grpc::string GetPeerIdentityPropertyName() const GRPC_OVERRIDE;

std::vector<grpc::string> FindPropertyValues(const grpc::string& name) const
GRPC_OVERRIDE;
std::vector<grpc::string_ref> FindPropertyValues(
const grpc::string& name) const GRPC_OVERRIDE;

AuthPropertyIterator begin() const GRPC_OVERRIDE;

Expand Down
15 changes: 9 additions & 6 deletions test/cpp/common/auth_property_iterator_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,14 @@
#include <grpc++/support/auth_context.h>
#include <gtest/gtest.h>
#include "src/cpp/common/secure_auth_context.h"
#include "test/cpp/util/string_ref_helper.h"

extern "C" {
#include "src/core/security/security_context.h"
}

using ::grpc::testing::ToString;

namespace grpc {
namespace {

Expand Down Expand Up @@ -84,12 +87,12 @@ TEST_F(AuthPropertyIteratorTest, GeneralTest) {
AuthProperty p1 = *iter;
iter++;
AuthProperty p2 = *iter;
EXPECT_EQ("name", p0.first);
EXPECT_EQ("chapi", p0.second);
EXPECT_EQ("name", p1.first);
EXPECT_EQ("chapo", p1.second);
EXPECT_EQ("foo", p2.first);
EXPECT_EQ("bar", p2.second);
EXPECT_EQ("name", ToString(p0.first));
EXPECT_EQ("chapi", ToString(p0.second));
EXPECT_EQ("name", ToString(p1.first));
EXPECT_EQ("chapo", ToString(p1.second));
EXPECT_EQ("foo", ToString(p2.first));
EXPECT_EQ("bar", ToString(p2.second));
++iter;
EXPECT_EQ(empty_iter, iter);
}
Expand Down
25 changes: 14 additions & 11 deletions test/cpp/common/secure_auth_context_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,14 @@
#include <grpc++/support/auth_context.h>
#include <gtest/gtest.h>
#include "src/cpp/common/secure_auth_context.h"
#include "test/cpp/util/string_ref_helper.h"

extern "C" {
#include "src/core/security/security_context.h"
}

using grpc::testing::ToString;

namespace grpc {
namespace {

Expand All @@ -63,14 +66,14 @@ TEST_F(SecureAuthContextTest, Properties) {
EXPECT_EQ(1, grpc_auth_context_set_peer_identity_property_name(ctx, "name"));

SecureAuthContext context(ctx);
std::vector<grpc::string> peer_identity = context.GetPeerIdentity();
std::vector<grpc::string_ref> peer_identity = context.GetPeerIdentity();
EXPECT_EQ(2u, peer_identity.size());
EXPECT_EQ("chapi", peer_identity[0]);
EXPECT_EQ("chapo", peer_identity[1]);
EXPECT_EQ("chapi", ToString(peer_identity[0]));
EXPECT_EQ("chapo", ToString(peer_identity[1]));
EXPECT_EQ("name", context.GetPeerIdentityPropertyName());
std::vector<grpc::string> bar = context.FindPropertyValues("foo");
std::vector<grpc::string_ref> bar = context.FindPropertyValues("foo");
EXPECT_EQ(1u, bar.size());
EXPECT_EQ("bar", bar[0]);
EXPECT_EQ("bar", ToString(bar[0]));
}

TEST_F(SecureAuthContextTest, Iterators) {
Expand All @@ -88,12 +91,12 @@ TEST_F(SecureAuthContextTest, Iterators) {
AuthProperty p1 = *iter;
iter++;
AuthProperty p2 = *iter;
EXPECT_EQ("name", p0.first);
EXPECT_EQ("chapi", p0.second);
EXPECT_EQ("name", p1.first);
EXPECT_EQ("chapo", p1.second);
EXPECT_EQ("foo", p2.first);
EXPECT_EQ("bar", p2.second);
EXPECT_EQ("name", ToString(p0.first));
EXPECT_EQ("chapi", ToString(p0.second));
EXPECT_EQ("name", ToString(p1.first));
EXPECT_EQ("chapo", ToString(p1.second));
EXPECT_EQ("foo", ToString(p2.first));
EXPECT_EQ("bar", ToString(p2.second));
++iter;
EXPECT_EQ(context.end(), iter);
}
Expand Down
15 changes: 8 additions & 7 deletions test/cpp/end2end/end2end_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ void MaybeEchoDeadline(ServerContext* context, const EchoRequest* request,

void CheckServerAuthContext(const ServerContext* context) {
std::shared_ptr<const AuthContext> auth_ctx = context->auth_context();
std::vector<grpc::string> ssl =
std::vector<grpc::string_ref> ssl =
auth_ctx->FindPropertyValues("transport_security_type");
EXPECT_EQ(1u, ssl.size());
EXPECT_EQ("ssl", ssl[0]);
EXPECT_EQ("ssl", ToString(ssl[0]));
EXPECT_TRUE(auth_ctx->GetPeerIdentityPropertyName().empty());
EXPECT_TRUE(auth_ctx->GetPeerIdentity().empty());
}
Expand Down Expand Up @@ -840,16 +840,17 @@ TEST_F(End2endTest, ClientAuthContext) {
EXPECT_TRUE(s.ok());

std::shared_ptr<const AuthContext> auth_ctx = context.auth_context();
std::vector<grpc::string> ssl =
std::vector<grpc::string_ref> ssl =
auth_ctx->FindPropertyValues("transport_security_type");
EXPECT_EQ(1u, ssl.size());
EXPECT_EQ("ssl", ssl[0]);
EXPECT_EQ("ssl", ToString(ssl[0]));
EXPECT_EQ("x509_subject_alternative_name",
auth_ctx->GetPeerIdentityPropertyName());
EXPECT_EQ(3u, auth_ctx->GetPeerIdentity().size());
EXPECT_EQ("*.test.google.fr", auth_ctx->GetPeerIdentity()[0]);
EXPECT_EQ("waterzooi.test.google.be", auth_ctx->GetPeerIdentity()[1]);
EXPECT_EQ("*.test.youtube.com", auth_ctx->GetPeerIdentity()[2]);
EXPECT_EQ("*.test.google.fr", ToString(auth_ctx->GetPeerIdentity()[0]));
EXPECT_EQ("waterzooi.test.google.be",
ToString(auth_ctx->GetPeerIdentity()[1]));
EXPECT_EQ("*.test.youtube.com", ToString(auth_ctx->GetPeerIdentity()[2]));
}

// Make the response larger than the flow control window.
Expand Down
10 changes: 8 additions & 2 deletions tools/run_tests/sources_and_headers.json
Original file line number Diff line number Diff line change
Expand Up @@ -1068,8 +1068,11 @@
{
"deps": [
"gpr",
"gpr_test_util",
"grpc",
"grpc++"
"grpc++",
"grpc++_test_util",
"grpc_test_util"
],
"headers": [],
"language": "c++",
Expand Down Expand Up @@ -1573,8 +1576,11 @@
{
"deps": [
"gpr",
"gpr_test_util",
"grpc",
"grpc++"
"grpc++",
"grpc++_test_util",
"grpc_test_util"
],
"headers": [],
"language": "c++",
Expand Down
8 changes: 4 additions & 4 deletions vsprojects/Grpc.mak
Original file line number Diff line number Diff line change
Expand Up @@ -615,10 +615,10 @@ async_end2end_test: async_end2end_test.exe
echo Running async_end2end_test
$(OUT_DIR)\async_end2end_test.exe

auth_property_iterator_test.exe: build_grpc++ build_grpc build_gpr $(OUT_DIR)
auth_property_iterator_test.exe: Debug\grpc++_test_util.lib build_grpc_test_util build_grpc++ build_grpc build_gpr_test_util build_gpr $(OUT_DIR)
echo Building auth_property_iterator_test
$(CC) $(CXXFLAGS) /Fo:$(OUT_DIR)\ $(REPO_ROOT)\test\cpp\common\auth_property_iterator_test.cc
$(LINK) $(LFLAGS) /OUT:"$(OUT_DIR)\auth_property_iterator_test.exe" Debug\grpc++.lib Debug\grpc.lib Debug\gpr.lib $(CXX_LIBS) $(LIBS) $(OUT_DIR)\auth_property_iterator_test.obj
$(LINK) $(LFLAGS) /OUT:"$(OUT_DIR)\auth_property_iterator_test.exe" Debug\grpc++_test_util.lib Debug\grpc_test_util.lib Debug\grpc++.lib Debug\grpc.lib Debug\gpr_test_util.lib Debug\gpr.lib $(CXX_LIBS) $(LIBS) $(OUT_DIR)\auth_property_iterator_test.obj
auth_property_iterator_test: auth_property_iterator_test.exe
echo Running auth_property_iterator_test
$(OUT_DIR)\auth_property_iterator_test.exe
Expand Down Expand Up @@ -751,10 +751,10 @@ reconnect_interop_server: reconnect_interop_server.exe
echo Running reconnect_interop_server
$(OUT_DIR)\reconnect_interop_server.exe

secure_auth_context_test.exe: build_grpc++ build_grpc build_gpr $(OUT_DIR)
secure_auth_context_test.exe: Debug\grpc++_test_util.lib build_grpc_test_util build_grpc++ build_grpc build_gpr_test_util build_gpr $(OUT_DIR)
echo Building secure_auth_context_test
$(CC) $(CXXFLAGS) /Fo:$(OUT_DIR)\ $(REPO_ROOT)\test\cpp\common\secure_auth_context_test.cc
$(LINK) $(LFLAGS) /OUT:"$(OUT_DIR)\secure_auth_context_test.exe" Debug\grpc++.lib Debug\grpc.lib Debug\gpr.lib $(CXX_LIBS) $(LIBS) $(OUT_DIR)\secure_auth_context_test.obj
$(LINK) $(LFLAGS) /OUT:"$(OUT_DIR)\secure_auth_context_test.exe" Debug\grpc++_test_util.lib Debug\grpc_test_util.lib Debug\grpc++.lib Debug\grpc.lib Debug\gpr_test_util.lib Debug\gpr.lib $(CXX_LIBS) $(LIBS) $(OUT_DIR)\secure_auth_context_test.obj
secure_auth_context_test: secure_auth_context_test.exe
echo Running secure_auth_context_test
$(OUT_DIR)\secure_auth_context_test.exe
Expand Down

0 comments on commit d090fe1

Please sign in to comment.