Return WAUTHN_ERROR_NOT_SUPPORTED for non-null options->hints 84/311584/7
authorKrzysztof Malysa <k.malysa@samsung.com>
Wed, 22 May 2024 14:31:47 +0000 (16:31 +0200)
committerKrzysztof Malysa <k.malysa@samsung.com>
Tue, 4 Jun 2024 15:15:08 +0000 (17:15 +0200)
Change-Id: I81fa54c6fcbde52ab36985e4afadb93b9f0d7f2b

srcs/request_handler.h
tests/request_handler_tests.cpp

index 67f8dae059537bf9d590dcf2e0555bd4b1cc5cfa..70fc3b9118d8499a438a1ab3846ed4c48e3746fb 100644 (file)
@@ -159,6 +159,8 @@ public:
         } else if (!request.options->linked_device && !request.callbacks->qrcode_callback) {
             TRY_LOG_ERROR("Missing qrcode_callback");
             result = WAUTHN_ERROR_INVALID_PARAMETER;
+        } else if (request.options->hints) {
+            result = WAUTHN_ERROR_NOT_SUPPORTED; // CTAP 2.2 does not specify any field for this
         } else {
             try {
                 if (request.options->linked_device) {
index a93d06d6ce9df6838b5a8019d018275fa6c621d1..fab399afe316aee56154b827a786e7950c61a94f 100644 (file)
@@ -412,27 +412,30 @@ void TestAll4Transactions(const PreTransactionCallback &preTransactionCallback,
     TestBothStateAssistedTransactions<Test>(preTransactionCallback, postTransactionCallback);
 }
 
-template <class WauthnCallbacks>
-struct InvalidParamsTest {
+template <class WauthnCallbacks, wauthn_error_e EXPECTED_ERROR>
+struct ErrorTest {
     std::string called;
     WauthnCallbacks callbacks = {
         [](const char *, void *) {
-            FAIL() << "qrcode_callback should not be called when parameters are invalid;";
+            FAIL() << "qrcode_callback should not be called when error happens;";
         },
         [](const auto *pubkeyCred, wauthn_error_e result, void *data) {
-            auto &test = *static_cast<InvalidParamsTest *>(data);
+            auto &test = *static_cast<ErrorTest *>(data);
             test.called += "response_callback;";
-            EXPECT_EQ(result, WAUTHN_ERROR_INVALID_PARAMETER);
+            EXPECT_EQ(result, EXPECTED_ERROR);
             EXPECT_EQ(pubkeyCred, nullptr);
         },
         [](const auto *, wauthn_error_e, void *) {
-            FAIL() << "linked_data_callback should not be called when parameters are invalid;";
+            FAIL() << "linked_data_callback should not be called when error happens;";
         },
         this,
     };
     WauthnCallbacks *callbacksPtr = &callbacks;
 };
 
+template <class WauthnCallbacks>
+using InvalidParamsTest = ErrorTest<WauthnCallbacks, WAUTHN_ERROR_INVALID_PARAMETER>;
+
 } // namespace
 
 TEST(RequestHandler, transaction_is_not_performed_with_nullptr_callbacks)
@@ -565,6 +568,28 @@ TEST(RequestHandler, transaction_is_not_performed_with_nullptr_options)
 
 namespace {
 
+template <class WauthnCallbacks>
+using UnsupportedParamTest = ErrorTest<WauthnCallbacks, WAUTHN_ERROR_NOT_SUPPORTED>;
+
+} // namespace
+
+TEST(RequestHandler, transaction_is_not_performed_if_options_hints_is_non_null)
+{
+    auto hints = wauthn_pubkey_cred_hints_s{0, nullptr};
+    TestAll4Transactions<UnsupportedParamTest>(
+        [&](auto &test, auto &options) {
+            test.options.hints = &hints;
+            options.mcResultProcessor = [&](auto &) { test.called += "result_processor;"; };
+            options.gaResultProcessor = [&](auto &) { test.called += "result_processor;"; };
+            options.followingCtapUpdatesProcessor = [&](auto &&) {
+                test.called += "update_processor;";
+            };
+        },
+        [](auto &test) { EXPECT_EQ(test.called, "response_callback;"); });
+}
+
+namespace {
+
 template <class WauthnCallbacks>
 struct QrCallbackTest {
     int counter = 0;