Skip to content

Commit

Permalink
fix(lint): lint new files
Browse files Browse the repository at this point in the history
  • Loading branch information
JMounier authored and tux3 committed Apr 15, 2024
1 parent de9d757 commit 733756f
Show file tree
Hide file tree
Showing 12 changed files with 94 additions and 86 deletions.
12 changes: 5 additions & 7 deletions modules/functional-tests/test_verification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -970,8 +970,7 @@ TEST_CASE_METHOD(TrustchainFixture, "authenticateWithIdp is restricted to truste

TC_AWAIT(enableOidc());
auto const oidcConfig = TestConstants::oidcConfig();
auto const providerId =
oidcProviderId(martineLaptop->sdkInfo().trustchainId, oidcConfig.issuer, oidcConfig.clientId);
auto const providerId = oidcProviderId(martineLaptop->sdkInfo().trustchainId, oidcConfig.issuer, oidcConfig.clientId);

REQUIRE(TC_AWAIT(martineLaptop->start(martine.identity)) == Status::IdentityRegistrationNeeded);
TANKER_CHECK_THROWS_WITH_CODE(TC_AWAIT(martineLaptop->authenticateWithIdp(providerId, "fake_oidc_subject=martine")),
Expand Down Expand Up @@ -1013,8 +1012,7 @@ TEST_CASE_METHOD(TrustchainFixture, "verification by oidc authorization code")
REQUIRE_NOTHROW(TC_AWAIT(martineLaptop->registerIdentity(verification)));

REQUIRE(TC_AWAIT(martinePhone->start(martine.identity)) == Status::IdentityVerificationNeeded);
TANKER_CHECK_THROWS_WITH_CODE(TC_AWAIT(martinePhone->verifyIdentity(verification)),
Errc::InvalidVerification);
TANKER_CHECK_THROWS_WITH_CODE(TC_AWAIT(martinePhone->verifyIdentity(verification)), Errc::InvalidVerification);
}

SECTION("fails to verify an oidc authorization code for the wrong user")
Expand All @@ -1023,10 +1021,10 @@ TEST_CASE_METHOD(TrustchainFixture, "verification by oidc authorization code")

REQUIRE_NOTHROW(TC_AWAIT(martineLaptop->registerIdentity(verification1)));

auto const verification2 = TC_AWAIT(martineLaptop->authenticateWithIdp(providerId, "fake_oidc_subject=not-martine"));
auto const verification2 =
TC_AWAIT(martineLaptop->authenticateWithIdp(providerId, "fake_oidc_subject=not-martine"));
REQUIRE(TC_AWAIT(martinePhone->start(martine.identity)) == Status::IdentityVerificationNeeded);
TANKER_CHECK_THROWS_WITH_CODE(TC_AWAIT(martinePhone->verifyIdentity(verification2)),
Errc::InvalidVerification);
TANKER_CHECK_THROWS_WITH_CODE(TC_AWAIT(martinePhone->verifyIdentity(verification2)), Errc::InvalidVerification);
}

SECTION("updates and verifies with an oidc authorization code")
Expand Down
3 changes: 2 additions & 1 deletion modules/sdk-core/include/Tanker/Network/HttpClient.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ class HttpClient
tc::cotask<HttpResult> asyncDelete(std::string_view target);

tc::cotask<HttpResult> asyncUnauthGet(std::string_view target);
tc::cotask<HttpResult> asyncUnauthGet(std::string_view target, std::pair<std::string const, std::string> const& header);
tc::cotask<HttpResult> asyncUnauthGet(std::string_view target,
std::pair<std::string const, std::string> const& header);
tc::cotask<HttpResult> asyncUnauthPost(std::string_view target, nlohmann::json data);

std::string makeUrl(std::string_view target) const;
Expand Down
5 changes: 3 additions & 2 deletions modules/sdk-core/include/Tanker/Oidc/IRequester.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ namespace Tanker::Oidc
class IRequester
{
public:
virtual tc::cotask<OidcAuthorizationCode>
oidcSignIn(Trustchain::UserId const& userId, std::string const& providerId, std::string const& cookie) = 0;
virtual tc::cotask<OidcAuthorizationCode> oidcSignIn(Trustchain::UserId const& userId,
std::string const& providerId,
std::string const& cookie) = 0;

virtual ~IRequester() = default;
};
Expand Down
5 changes: 3 additions & 2 deletions modules/sdk-core/include/Tanker/Oidc/Requester.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ class Requester : public IRequester
public:
Requester(Network::HttpClient* httpClient);

tc::cotask<OidcAuthorizationCode>
oidcSignIn(Trustchain::UserId const& userId, std::string const& providerId, std::string const& cookie) override;
tc::cotask<OidcAuthorizationCode> oidcSignIn(Trustchain::UserId const& userId,
std::string const& providerId,
std::string const& cookie) override;

private:
Network::HttpClient* _httpClient;
Expand Down
6 changes: 5 additions & 1 deletion modules/sdk-core/include/Tanker/Session.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ namespace Tanker
class Session
{
public:
struct Requesters : Users::Requester, Groups::Requester, ProvisionalUsers::Requester, Verification::Requester, Oidc::Requester
struct Requesters : Users::Requester,
Groups::Requester,
ProvisionalUsers::Requester,
Verification::Requester,
Oidc::Requester

{
Requesters(Network::HttpClient*);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
#include <Tanker/Types/EncryptedPhoneNumber.hpp>
#include <Tanker/Types/EncryptedPreverifiedEmail.hpp>
#include <Tanker/Types/EncryptedPreverifiedPhoneNumber.hpp>
#include <Tanker/Types/OidcAuthorizationCode.hpp>
#include <Tanker/Types/OidcIdToken.hpp>
#include <Tanker/Types/OidcNonce.hpp>
#include <Tanker/Types/OidcAuthorizationCode.hpp>
#include <Tanker/Types/Passphrase.hpp>
#include <Tanker/Types/PhoneNumber.hpp>
#include <Tanker/Types/PreverifiedEmail.hpp>
Expand Down
3 changes: 2 additions & 1 deletion modules/sdk-core/src/AsyncCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,8 @@ tc::future<void> AsyncCore::verifyProvisionalIdentity(Verification::Verification
[=, this]() -> tc::cotask<void> { TC_AWAIT(this->_core.verifyProvisionalIdentity(verification)); });
}

tc::future<OidcAuthorizationCode> AsyncCore::authenticateWithIdp(std::string const& provider_id, std::string const& cookie)
tc::future<OidcAuthorizationCode> AsyncCore::authenticateWithIdp(std::string const& provider_id,
std::string const& cookie)
{
return runResumable([=, this]() -> tc::cotask<OidcAuthorizationCode> {
TC_RETURN(TC_AWAIT(this->_core.authenticateWithIdp(provider_id, cookie)));
Expand Down
7 changes: 3 additions & 4 deletions modules/sdk-core/src/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -950,10 +950,9 @@ tc::cotask<void> Core::verifyProvisionalIdentity(Verification::Verification cons

tc::cotask<OidcAuthorizationCode> Core::authenticateWithIdp(std::string const& providerId, std::string const& cookie)
{
assertStatus({Status::IdentityRegistrationNeeded, Status::IdentityVerificationNeeded, Status::Ready}, "authenticateWithIdp");
TC_RETURN(TC_AWAIT(
_session->requesters().oidcSignIn(_session->userId(), providerId, cookie)
));
assertStatus({Status::IdentityRegistrationNeeded, Status::IdentityVerificationNeeded, Status::Ready},
"authenticateWithIdp");
TC_RETURN(TC_AWAIT(_session->requesters().oidcSignIn(_session->userId(), providerId, cookie)));
}

void Core::nukeDatabase()
Expand Down
11 changes: 6 additions & 5 deletions modules/sdk-core/src/Network/HttpClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ boost::container::flat_map<std::string_view, AppdErrc> const appdErrorMap{
{"missing_user_group_members", AppdErrc::MissingUserGroupMembers},
{"feature_not_enabled", AppdErrc::FeatureNotEnabled},
{"conflict", AppdErrc::Conflict},
{"invalid_authorization_code",AppdErrc::InvalidAuthorizationCode},
{"oidc_provider_interaction_required",AppdErrc::OidcProviderInteractionRequired},
{"oidc_provider_not_configured",AppdErrc::OidcProviderNotConfigured},
{"oidc_provider_not_supported",AppdErrc::OidcProviderNotSupported},
{"invalid_authorization_code", AppdErrc::InvalidAuthorizationCode},
{"oidc_provider_interaction_required", AppdErrc::OidcProviderInteractionRequired},
{"oidc_provider_not_configured", AppdErrc::OidcProviderNotConfigured},
{"oidc_provider_not_supported", AppdErrc::OidcProviderNotSupported},
};

AppdErrc getErrorFromCode(std::string_view code)
Expand Down Expand Up @@ -302,7 +302,8 @@ tc::cotask<HttpResult> HttpClient::asyncUnauthGet(std::string_view target)
TC_RETURN(TC_AWAIT(fetch(std::move(req))));
}

tc::cotask<HttpResult> HttpClient::asyncUnauthGet(std::string_view target, std::pair<std::string const, std::string> const& header)
tc::cotask<HttpResult> HttpClient::asyncUnauthGet(std::string_view target,
std::pair<std::string const, std::string> const& header)
{
auto req = makeRequest(HttpMethod::Get, target);
req.headers.set(header);
Expand Down
13 changes: 8 additions & 5 deletions modules/sdk-core/src/Oidc/Requester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,18 @@ Requester::Requester(Network::HttpClient* httpClient) : _httpClient(httpClient)
{
}

tc::cotask<OidcAuthorizationCode> Requester::oidcSignIn(Trustchain::UserId const& userId, std::string const& providerId, std::string const& cookie)
tc::cotask<OidcAuthorizationCode> Requester::oidcSignIn(Trustchain::UserId const& userId,
std::string const& providerId,
std::string const& cookie)
{
auto const query =
nlohmann::json{{"user_id", mgs::base64url_nopad::encode(userId)}};
auto signinUrl = _httpClient->makeUrl(fmt::format("oidc/{providerId}/signin", fmt::arg("providerId", providerId)), query);
auto const query = nlohmann::json{{"user_id", mgs::base64url_nopad::encode(userId)}};
auto signinUrl =
_httpClient->makeUrl(fmt::format("oidc/{providerId}/signin", fmt::arg("providerId", providerId)), query);
auto const signinResponse = TC_AWAIT(_httpClient->asyncUnauthGet(signinUrl)).value();

auto const authorizationLocation = signinResponse.at("location").get<std::string>();
auto const authorizationResponse = TC_AWAIT(_httpClient->asyncUnauthGet(authorizationLocation, {"Cookie", cookie})).value();
auto const authorizationResponse =
TC_AWAIT(_httpClient->asyncUnauthGet(authorizationLocation, {"Cookie", cookie})).value();

auto const callbackLocation = authorizationResponse.at("location").get<std::string>();
auto const resp = TC_AWAIT(_httpClient->asyncUnauthGet(callbackLocation)).value();
Expand Down
110 changes: 54 additions & 56 deletions modules/sdk-core/src/Verification/Request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ RequestWithVerif makeRequestWithVerif(RequestVerification const& verification,
checkNotEmpty(v.authorization_code, "oidcAuthorizationCode");
checkNotEmpty(v.state, "oidcState");
return v;
} ,
},
},
verification);
return {verif, withTokenNonce};
Expand Down Expand Up @@ -230,61 +230,59 @@ void adl_serializer<Tanker::Verification::RequestVerificationPayload>::to_json(
json& j, Tanker::Verification::RequestVerificationPayload const& request)
{
using namespace Tanker;
boost::variant2::visit(overloaded{
[&](Verification::EncryptedEmailVerification const& e) {
j["hashed_email"] = e.hashedEmail;
j["verification_code"] = e.verificationCode;
j["v2_encrypted_email"] = e.encryptedEmail;
},
[&](Verification::EncryptedPhoneNumberVerification const& e) {
j["phone_number"] = e.phoneNumber;
j["verification_code"] = e.verificationCode;
j["encrypted_phone_number"] = e.encryptedPhoneNumber;
j["user_salt"] = e.userSalt;
if (e.provisionalSalt)
{
j["provisional_salt"] = *e.provisionalSalt;
}
},
[&](Trustchain::HashedPassphrase const& p) { j["hashed_passphrase"] = p; },
[&](Trustchain::HashedE2ePassphrase const& p) { j["hashed_e2e_passphrase"] = p; },
[&](OidcIdToken const& t) { j["oidc_id_token"] = t.token; },
[&](Verification::OidcIdTokenWithChallenge const& t) {
j["oidc_id_token"] = t.oidcIdToken.token;
j["oidc_challenge"] = t.oidcChallenge.challenge;
j["oidc_challenge_signature"] = t.oidcChallenge.signature;
if (t.oidcTestNonce)
{
j["oidc_test_nonce"] = *t.oidcTestNonce;
}
},
[](VerificationKey const& v) {},
[&](Verification::EncryptedPreverifiedEmailVerification const& e) {
j["hashed_email"] = e.hashedEmail;
j["v2_encrypted_email"] = e.encryptedEmail;
j["is_preverified"] = true;
},
[&](Verification::EncryptedPreverifiedPhoneNumberVerification const& e) {
j["phone_number"] = e.phoneNumber;
j["encrypted_phone_number"] = e.encryptedPhoneNumber;
j["user_salt"] = e.userSalt;
j["is_preverified"] = true;
if (e.provisionalSalt)
{
j["provisional_salt"] = *e.provisionalSalt;
}
},
[&](PreverifiedOidc const& e) {
j["oidc_provider_id"] = e.provider_id;
j["oidc_subject"] = e.subject;
j["is_preverified"] = true;
},
[&](OidcAuthorizationCode const& o) {
j["oidc_provider_id"] = o.provider_id;
j["oidc_authorization_code"] = o.authorization_code;
j["oidc_state"] = o.state;
}
},
boost::variant2::visit(overloaded{[&](Verification::EncryptedEmailVerification const& e) {
j["hashed_email"] = e.hashedEmail;
j["verification_code"] = e.verificationCode;
j["v2_encrypted_email"] = e.encryptedEmail;
},
[&](Verification::EncryptedPhoneNumberVerification const& e) {
j["phone_number"] = e.phoneNumber;
j["verification_code"] = e.verificationCode;
j["encrypted_phone_number"] = e.encryptedPhoneNumber;
j["user_salt"] = e.userSalt;
if (e.provisionalSalt)
{
j["provisional_salt"] = *e.provisionalSalt;
}
},
[&](Trustchain::HashedPassphrase const& p) { j["hashed_passphrase"] = p; },
[&](Trustchain::HashedE2ePassphrase const& p) { j["hashed_e2e_passphrase"] = p; },
[&](OidcIdToken const& t) { j["oidc_id_token"] = t.token; },
[&](Verification::OidcIdTokenWithChallenge const& t) {
j["oidc_id_token"] = t.oidcIdToken.token;
j["oidc_challenge"] = t.oidcChallenge.challenge;
j["oidc_challenge_signature"] = t.oidcChallenge.signature;
if (t.oidcTestNonce)
{
j["oidc_test_nonce"] = *t.oidcTestNonce;
}
},
[](VerificationKey const& v) {},
[&](Verification::EncryptedPreverifiedEmailVerification const& e) {
j["hashed_email"] = e.hashedEmail;
j["v2_encrypted_email"] = e.encryptedEmail;
j["is_preverified"] = true;
},
[&](Verification::EncryptedPreverifiedPhoneNumberVerification const& e) {
j["phone_number"] = e.phoneNumber;
j["encrypted_phone_number"] = e.encryptedPhoneNumber;
j["user_salt"] = e.userSalt;
j["is_preverified"] = true;
if (e.provisionalSalt)
{
j["provisional_salt"] = *e.provisionalSalt;
}
},
[&](PreverifiedOidc const& e) {
j["oidc_provider_id"] = e.provider_id;
j["oidc_subject"] = e.subject;
j["is_preverified"] = true;
},
[&](OidcAuthorizationCode const& o) {
j["oidc_provider_id"] = o.provider_id;
j["oidc_authorization_code"] = o.authorization_code;
j["oidc_state"] = o.state;
}},
request);
}

Expand Down
3 changes: 2 additions & 1 deletion modules/types/include/Tanker/Types/OidcAuthorizationCode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ struct OidcAuthorizationCode

inline bool operator==(OidcAuthorizationCode const& lhs, OidcAuthorizationCode const& rhs) noexcept
{
return lhs.provider_id == rhs.provider_id && lhs.authorization_code == rhs.authorization_code && lhs.state == rhs.state;
return lhs.provider_id == rhs.provider_id && lhs.authorization_code == rhs.authorization_code &&
lhs.state == rhs.state;
}

inline bool operator!=(OidcAuthorizationCode const& lhs, OidcAuthorizationCode const& rhs) noexcept
Expand Down

0 comments on commit 733756f

Please sign in to comment.