From 733756faf6a5a46eea3f0e96d24685c471d14753 Mon Sep 17 00:00:00 2001 From: julien mounier Date: Thu, 21 Mar 2024 15:06:13 +0100 Subject: [PATCH] fix(lint): lint new files --- .../functional-tests/test_verification.cpp | 12 +- .../include/Tanker/Network/HttpClient.hpp | 3 +- .../include/Tanker/Oidc/IRequester.hpp | 5 +- .../include/Tanker/Oidc/Requester.hpp | 5 +- modules/sdk-core/include/Tanker/Session.hpp | 6 +- .../Tanker/Verification/Verification.hpp | 2 +- modules/sdk-core/src/AsyncCore.cpp | 3 +- modules/sdk-core/src/Core.cpp | 7 +- modules/sdk-core/src/Network/HttpClient.cpp | 11 +- modules/sdk-core/src/Oidc/Requester.cpp | 13 ++- modules/sdk-core/src/Verification/Request.cpp | 110 +++++++++--------- .../Tanker/Types/OidcAuthorizationCode.hpp | 3 +- 12 files changed, 94 insertions(+), 86 deletions(-) diff --git a/modules/functional-tests/test_verification.cpp b/modules/functional-tests/test_verification.cpp index 6fc37c903..84c0c11b4 100644 --- a/modules/functional-tests/test_verification.cpp +++ b/modules/functional-tests/test_verification.cpp @@ -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")), @@ -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") @@ -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") diff --git a/modules/sdk-core/include/Tanker/Network/HttpClient.hpp b/modules/sdk-core/include/Tanker/Network/HttpClient.hpp index 633a789e0..520f66d48 100644 --- a/modules/sdk-core/include/Tanker/Network/HttpClient.hpp +++ b/modules/sdk-core/include/Tanker/Network/HttpClient.hpp @@ -61,7 +61,8 @@ class HttpClient tc::cotask asyncDelete(std::string_view target); tc::cotask asyncUnauthGet(std::string_view target); - tc::cotask asyncUnauthGet(std::string_view target, std::pair const& header); + tc::cotask asyncUnauthGet(std::string_view target, + std::pair const& header); tc::cotask asyncUnauthPost(std::string_view target, nlohmann::json data); std::string makeUrl(std::string_view target) const; diff --git a/modules/sdk-core/include/Tanker/Oidc/IRequester.hpp b/modules/sdk-core/include/Tanker/Oidc/IRequester.hpp index f75eed508..b191a5eba 100644 --- a/modules/sdk-core/include/Tanker/Oidc/IRequester.hpp +++ b/modules/sdk-core/include/Tanker/Oidc/IRequester.hpp @@ -11,8 +11,9 @@ namespace Tanker::Oidc class IRequester { public: - virtual tc::cotask - oidcSignIn(Trustchain::UserId const& userId, std::string const& providerId, std::string const& cookie) = 0; + virtual tc::cotask oidcSignIn(Trustchain::UserId const& userId, + std::string const& providerId, + std::string const& cookie) = 0; virtual ~IRequester() = default; }; diff --git a/modules/sdk-core/include/Tanker/Oidc/Requester.hpp b/modules/sdk-core/include/Tanker/Oidc/Requester.hpp index 4d30160c6..a41161136 100644 --- a/modules/sdk-core/include/Tanker/Oidc/Requester.hpp +++ b/modules/sdk-core/include/Tanker/Oidc/Requester.hpp @@ -26,8 +26,9 @@ class Requester : public IRequester public: Requester(Network::HttpClient* httpClient); - tc::cotask - oidcSignIn(Trustchain::UserId const& userId, std::string const& providerId, std::string const& cookie) override; + tc::cotask oidcSignIn(Trustchain::UserId const& userId, + std::string const& providerId, + std::string const& cookie) override; private: Network::HttpClient* _httpClient; diff --git a/modules/sdk-core/include/Tanker/Session.hpp b/modules/sdk-core/include/Tanker/Session.hpp index 835ab4ba0..dbd2907d9 100644 --- a/modules/sdk-core/include/Tanker/Session.hpp +++ b/modules/sdk-core/include/Tanker/Session.hpp @@ -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*); diff --git a/modules/sdk-core/include/Tanker/Verification/Verification.hpp b/modules/sdk-core/include/Tanker/Verification/Verification.hpp index b97a06005..60fa29700 100644 --- a/modules/sdk-core/include/Tanker/Verification/Verification.hpp +++ b/modules/sdk-core/include/Tanker/Verification/Verification.hpp @@ -8,9 +8,9 @@ #include #include #include +#include #include #include -#include #include #include #include diff --git a/modules/sdk-core/src/AsyncCore.cpp b/modules/sdk-core/src/AsyncCore.cpp index 64146342d..315727ffc 100644 --- a/modules/sdk-core/src/AsyncCore.cpp +++ b/modules/sdk-core/src/AsyncCore.cpp @@ -288,7 +288,8 @@ tc::future AsyncCore::verifyProvisionalIdentity(Verification::Verification [=, this]() -> tc::cotask { TC_AWAIT(this->_core.verifyProvisionalIdentity(verification)); }); } -tc::future AsyncCore::authenticateWithIdp(std::string const& provider_id, std::string const& cookie) +tc::future AsyncCore::authenticateWithIdp(std::string const& provider_id, + std::string const& cookie) { return runResumable([=, this]() -> tc::cotask { TC_RETURN(TC_AWAIT(this->_core.authenticateWithIdp(provider_id, cookie))); diff --git a/modules/sdk-core/src/Core.cpp b/modules/sdk-core/src/Core.cpp index e1bd3f1b9..1c2a0a7eb 100644 --- a/modules/sdk-core/src/Core.cpp +++ b/modules/sdk-core/src/Core.cpp @@ -950,10 +950,9 @@ tc::cotask Core::verifyProvisionalIdentity(Verification::Verification cons tc::cotask 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() diff --git a/modules/sdk-core/src/Network/HttpClient.cpp b/modules/sdk-core/src/Network/HttpClient.cpp index c7b14e905..abbe33ca6 100644 --- a/modules/sdk-core/src/Network/HttpClient.cpp +++ b/modules/sdk-core/src/Network/HttpClient.cpp @@ -53,10 +53,10 @@ boost::container::flat_map 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) @@ -302,7 +302,8 @@ tc::cotask HttpClient::asyncUnauthGet(std::string_view target) TC_RETURN(TC_AWAIT(fetch(std::move(req)))); } -tc::cotask HttpClient::asyncUnauthGet(std::string_view target, std::pair const& header) +tc::cotask HttpClient::asyncUnauthGet(std::string_view target, + std::pair const& header) { auto req = makeRequest(HttpMethod::Get, target); req.headers.set(header); diff --git a/modules/sdk-core/src/Oidc/Requester.cpp b/modules/sdk-core/src/Oidc/Requester.cpp index bc7471ddf..63d3b8f69 100644 --- a/modules/sdk-core/src/Oidc/Requester.cpp +++ b/modules/sdk-core/src/Oidc/Requester.cpp @@ -17,15 +17,18 @@ Requester::Requester(Network::HttpClient* httpClient) : _httpClient(httpClient) { } -tc::cotask Requester::oidcSignIn(Trustchain::UserId const& userId, std::string const& providerId, std::string const& cookie) +tc::cotask 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(); - 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(); auto const resp = TC_AWAIT(_httpClient->asyncUnauthGet(callbackLocation)).value(); diff --git a/modules/sdk-core/src/Verification/Request.cpp b/modules/sdk-core/src/Verification/Request.cpp index 9fa810044..a5ac63ca9 100644 --- a/modules/sdk-core/src/Verification/Request.cpp +++ b/modules/sdk-core/src/Verification/Request.cpp @@ -140,7 +140,7 @@ RequestWithVerif makeRequestWithVerif(RequestVerification const& verification, checkNotEmpty(v.authorization_code, "oidcAuthorizationCode"); checkNotEmpty(v.state, "oidcState"); return v; - } , + }, }, verification); return {verif, withTokenNonce}; @@ -230,61 +230,59 @@ void adl_serializer::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); } diff --git a/modules/types/include/Tanker/Types/OidcAuthorizationCode.hpp b/modules/types/include/Tanker/Types/OidcAuthorizationCode.hpp index 6aaef7215..e64321491 100644 --- a/modules/types/include/Tanker/Types/OidcAuthorizationCode.hpp +++ b/modules/types/include/Tanker/Types/OidcAuthorizationCode.hpp @@ -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