Skip to content

Commit

Permalink
Fix a memory management mistake in oidc_filter_test.cc
Browse files Browse the repository at this point in the history
- Remove an unused include in in_memory_session_store_test.cc
- Add a new target in the Makefile to help run focused tests from
  the command line

[Issue #69]

Signed-off-by: Ryan Richard <rrichard@pivotal.io>
  • Loading branch information
Changdrew authored and cfryanr committed Feb 26, 2020
1 parent faef663 commit 70f531b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,14 @@ run:
bazel run $(BAZEL_FLAGS) $(TARGET)

test:
bazel test $(BAZEL_FLAGS) --strategy=TestRunner=standalone --test_output=all //test/...
bazel test $(BAZEL_FLAGS) --strategy=TestRunner=standalone --test_output=all --cache_test_results=no //test/...

# Only run tests whose name matches a filter
# Usage examples:
# make filter-test FILTER=*RetrieveToken*
# make filter-test FILTER=OidcFilterTest.*
filter-test:
bazel test $(BAZEL_FLAGS) --strategy=TestRunner=standalone --test_output=all --cache_test_results=no //test/... --test_arg='--gtest_filter=$(FILTER)'

coverage:
bazel coverage $(BAZEL_FLAGS) --instrumentation_filter=//src/ //...
Expand Down
1 change: 0 additions & 1 deletion test/filters/oidc/in_memory_session_store_test.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include <thread>
#include <include/gmock/gmock-actions.h>
#include <spdlog/spdlog.h>
#include "gtest/gtest.h"
#include "src/filters/oidc/in_memory_session_store.h"
#include "test/common/utilities/mocks.h"
Expand Down
21 changes: 10 additions & 11 deletions test/filters/oidc/oidc_filter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -259,12 +259,12 @@ TEST_F(OidcFilterTest, ShouldRedirectToIdpToAuthenticateAgain_WhenAccessTokenIsM
auto state = "some-state";
auto nonce = "some-nonce";
MockSessionGenerator(new_session_id, state, nonce);

TokenResponse token_response(test_id_token_jwt_);
token_response.SetAccessTokenExpiry(2906139022); //Feb 2, 2062
token_response.SetAccessToken(nullptr);
session_store_->SetTokenResponse(old_session_id, std::make_shared<TokenResponse>(token_response));

OidcFilter filter(common::http::ptr_t(), config_, parser_mock_, session_string_generator_mock_, session_store_);
auto httpRequest = request_.mutable_attributes()->mutable_request()->mutable_http();
httpRequest->mutable_headers()->insert(
Expand Down Expand Up @@ -750,7 +750,7 @@ TEST_F(OidcFilterTest, RetrieveToken_ReturnsError_WhenAuthorizationStateInfoCann
httpRequest->set_host(callback_host_on_request);
httpRequest->mutable_headers()->insert(
{common::http::headers::Cookie, "__Host-cookie-prefix-authservice-session-id-cookie=" + session_id});
std::vector<absl::string_view> parts = {oidcConfig.callback().path().c_str(), "code=value&state=some-state-value"};
std::vector<std::string> parts = {oidcConfig.callback().path(), "code=value&state=some-state-value"};
httpRequest->set_path(absl::StrJoin(parts, "?"));

auto code = filter.Process(&request_, &response_);
Expand Down Expand Up @@ -784,7 +784,7 @@ TEST_F(OidcFilterTest, RetrieveToken_ReturnsError_WhenTokenResponseIsMissingAcce
httpRequest->mutable_headers()->insert(
{common::http::headers::Cookie, "__Host-cookie-prefix-authservice-session-id-cookie=" + session_id});

std::vector<absl::string_view> parts = {config_.callback().path().c_str(), "code=value&state=" + state};
std::vector<std::string> parts = {config_.callback().path(), "code=value&state=" + state};
httpRequest->set_path(absl::StrJoin(parts, "?"));
auto code = filter.Process(&request_, &response_);
ASSERT_EQ(code, google::rpc::Code::INVALID_ARGUMENT);
Expand Down Expand Up @@ -813,7 +813,7 @@ TEST_F(OidcFilterTest, RetrieveToken_ReturnsError_WhenMissingCode) {
request_.mutable_attributes()->mutable_request()->mutable_http();
httpRequest->set_host(callback_host_);
httpRequest->set_path(config_.callback().path());
std::vector<absl::string_view> parts = {config_.callback().path().c_str(), "key=value&state=" + state};
std::vector<std::string> parts = {config_.callback().path(), "key=value&state=" + state};
httpRequest->set_path(absl::StrJoin(parts, "?"));
httpRequest->mutable_headers()->insert(
{common::http::headers::Cookie, "__Host-cookie-prefix-authservice-session-id-cookie=" + session_id});
Expand All @@ -836,8 +836,7 @@ TEST_F(OidcFilterTest, RetrieveToken_ReturnsError_WhenMissingState) {
request_.mutable_attributes()->mutable_request()->mutable_http();
httpRequest->set_host(callback_host_);
httpRequest->set_path(config_.callback().path());
std::vector<absl::string_view> parts = {config_.callback().path().c_str(),
"code=value"};
std::vector<std::string> parts = {config_.callback().path().c_str(), "code=value"};
httpRequest->set_path(absl::StrJoin(parts, "?"));
httpRequest->mutable_headers()->insert(
{common::http::headers::Cookie,
Expand Down Expand Up @@ -868,7 +867,7 @@ TEST_F(OidcFilterTest, RetrieveToken_ReturnsError_WhenUnexpectedState) {
request_.mutable_attributes()->mutable_request()->mutable_http();
httpRequest->set_host(callback_host_);
httpRequest->set_path(config_.callback().path());
std::vector<absl::string_view> parts = {config_.callback().path().c_str(), "code=value&state=unexpectedstate"};
std::vector<std::string> parts = {config_.callback().path(), "code=value&state=unexpectedstate"};
httpRequest->set_path(absl::StrJoin(parts, "?"));
httpRequest->mutable_headers()->insert(
{common::http::headers::Cookie, "__Host-cookie-prefix-authservice-session-id-cookie=" + session_id});
Expand Down Expand Up @@ -904,7 +903,7 @@ TEST_F(OidcFilterTest, RetrieveToken_ReturnsError_WhenBrokenPipe) {
httpRequest->set_path(config_.callback().path());
httpRequest->mutable_headers()->insert(
{common::http::headers::Cookie, "__Host-cookie-prefix-authservice-session-id-cookie=" + session_id});
std::vector<absl::string_view> parts = {config_.callback().path().c_str(), "code=value&state=" + state};
std::vector<std::string> parts = {config_.callback().path(), "code=value&state=" + state};
httpRequest->set_path(absl::StrJoin(parts, "?"));
auto code = filter.Process(&request_, &response_);
ASSERT_EQ(code, google::rpc::Code::INTERNAL);
Expand Down Expand Up @@ -940,7 +939,7 @@ TEST_F(OidcFilterTest, RetrieveToken_ReturnsError_WhenInvalidResponse) {
httpRequest->set_path(config_.callback().path());
httpRequest->mutable_headers()->insert(
{common::http::headers::Cookie, "__Host-cookie-prefix-authservice-session-id-cookie=" + session_id});
std::vector<absl::string_view> parts = {config_.callback().path().c_str(), "code=value&state=" + state};
std::vector<std::string> parts = {config_.callback().path(), "code=value&state=" + state};
httpRequest->set_path(absl::StrJoin(parts, "?"));
auto code = filter.Process(&request_, &response_);
ASSERT_EQ(code, google::rpc::Code::INVALID_ARGUMENT);
Expand Down Expand Up @@ -1002,7 +1001,7 @@ void OidcFilterTest::AssertRetrieveToken(config::oidc::OIDCConfig &oidcConfig, s
httpRequest->set_host(callback_host_on_request);
httpRequest->mutable_headers()->insert(
{common::http::headers::Cookie, "__Host-cookie-prefix-authservice-session-id-cookie=" + session_id});
std::vector<absl::string_view> parts = {oidcConfig.callback().path().c_str(), "code=value&state=" + state};
std::vector<std::string> parts = {oidcConfig.callback().path(), "code=value&state=" + state};
httpRequest->set_path(absl::StrJoin(parts, "?"));

auto code = filter.Process(&request_, &response_);
Expand Down

0 comments on commit 70f531b

Please sign in to comment.