Skip to content

Commit

Permalink
make tests functional
Browse files Browse the repository at this point in the history
  • Loading branch information
sbera87 committed Sep 6, 2024
1 parent ca282bb commit f6111ca
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,20 @@
namespace smithy {
class AwsBearerTokenIdentity : public AwsBearerTokenIdentityBase {
public:
virtual Aws::String token() const override;

virtual const Aws::String& token() const override;

virtual Aws::Crt::Optional<AwsIdentity::DateTime> expiration() const override;

Aws::String& token(){
return m_token;
}

Aws::Crt::Optional<AwsIdentity::DateTime>& expiration(){
return m_expiration;
}


protected:
Aws::String m_token;
Aws::Crt::Optional<AwsIdentity::DateTime> m_expiration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace smithy {
class AwsBearerTokenIdentityBase : public AwsIdentity {
public:
virtual Aws::String token() const = 0;
virtual const Aws::String& token() const = 0;

virtual Aws::Crt::Optional<AwsIdentity::DateTime> expiration() const override = 0 ;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <smithy/identity/identity/AwsBearerTokenIdentity.h>

namespace smithy {
Aws::String AwsBearerTokenIdentity::token() const {
const Aws::String& AwsBearerTokenIdentity::token() const {
return m_token;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ namespace smithy {
using IdentityT = AwsBearerTokenIdentity;
virtual ~AwsBearerTokenIdentityResolver() = default;

AwsBearerTokenIdentityResolver() = default;

AwsBearerTokenIdentityResolver(const Aws::Vector<std::shared_ptr<Aws::Auth::AWSBearerTokenProviderBase> >& providerChain) : m_providerChainLegacy{providerChain}
{

Expand Down
20 changes: 11 additions & 9 deletions tests/aws-cpp-sdk-core-tests/smithy/client/SmithyClientTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class SmithyClientTest : public Aws::Testing::AwsCppSdkGTestSuite {
};



//====================bearer token ===============================
class TestSSOBearerTokenProvider : public Aws::Auth::AWSBearerTokenProviderBase
{
public:
Expand All @@ -95,14 +95,14 @@ class TestSSOBearerTokenProvider : public Aws::Auth::AWSBearerTokenProviderBase
}
};

class TestAwsBearerTokenIdentityResolver : smithy::DefaultAwsBearerTokenIdentityResolver
class TestAwsBearerTokenIdentityResolver : public smithy::DefaultAwsBearerTokenIdentityResolver
{
public:
TestAwsBearerTokenIdentityResolver():DefaultAwsBearerTokenIdentityResolver(){
TestAwsBearerTokenIdentityResolver(): smithy::DefaultAwsBearerTokenIdentityResolver(){
AddBearerTokenProvider(Aws::MakeShared<TestSSOBearerTokenProvider>(ALLOC_TAG));
}
};

//===============================================================
const char SmithyClientTest::ALLOCATION_TAG[] = "SmithyClientTest";


Expand Down Expand Up @@ -255,8 +255,6 @@ TEST_F(SmithyClientTest, testSigV4a) {
EXPECT_FALSE(res2.GetResult()->GetUri().GetURIString(true).empty());

}
// using AwsCredentialIdentityResolverT = IdentityResolverBase<IdentityT>;
// using AwsCredentialSignerT = AwsSignerBase<IdentityT>;

TEST_F(SmithyClientTest, bearer) {

Expand All @@ -265,9 +263,10 @@ TEST_F(SmithyClientTest, bearer) {
Aws::UnorderedMap<Aws::String, SigVariant> authSchemesMap;

Aws::String key{"Bearer"};
auto credentialsResolver = Aws::MakeShared<TestAwsBearerTokenIdentityResolver>(ALLOCATION_TAG);

SigVariant val{smithy::BearerTokenAuthScheme(credentialsResolver, "MyService", "us-west-2")};
std::shared_ptr<smithy::AwsBearerTokenIdentityResolver> resolver = Aws::MakeShared<TestAwsBearerTokenIdentityResolver>(ALLOCATION_TAG);

SigVariant val{smithy::BearerTokenAuthScheme(resolver, "MyService", "us-west-2")};

authSchemesMap.emplace(key, val);

Expand Down Expand Up @@ -298,7 +297,10 @@ TEST_F(SmithyClientTest, bearer) {
auto res2 = ptr->SignRequest(httpRequest, res.GetResult());

EXPECT_EQ(res2.IsSuccess(), true);


EXPECT_TRUE(!res2.GetResult()->GetHeaderValue("authorization").empty());

std::cout<<"header="<<res2.GetResult()->GetHeaderValue("authorization")<<std::endl;

//EXPECT_TRUE(res2.GetResult()->GetSigningAccessKey().empty());

Expand Down

0 comments on commit f6111ca

Please sign in to comment.