shibd commented on code in PR #249:
URL: https://github.com/apache/pulsar-client-cpp/pull/249#discussion_r1166643609


##########
.github/workflows/ci-pr-validation.yaml:
##########
@@ -93,6 +93,14 @@ jobs:
       - name: Build
         run: make -j8
 
+      - name: Run OAuth2 tests
+        run: |
+          docker compose -f tests/oauth2/docker-compose.yml up -d

Review Comment:
   It's better to keep it consistent with how originally run unit tests.
   
   1. Run `Oauth2` standalone broker on `pulsar-test-service-start.sh`.
   2. No additional link `Oauth2Test.cc` is necessary. 
   
   This provides the following benefits
   1. Developers can run all tests via `pulsar-test-service-start.sh` scripts.
   2. It is not necessary to add this step separately to the CI: `Run OAuth2 
tests`
   3. In the future, if there are other related tests of Oauth2, this broker 
can be reused.
   
   
   



##########
tests/oauth2/docker-compose.yml:
##########
@@ -0,0 +1,46 @@
+#

Review Comment:
   We can move this file to `tests-conf`.



##########
tests/oauth2/Oauth2Test.cc:
##########
@@ -0,0 +1,87 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+// Run `docker-compose up -d` to set up the test environment for this test.
+#include <gtest/gtest.h>
+#include <pulsar/Client.h>
+
+#include <cstdio>
+#include <fstream>
+#include <string>
+
+#include "lib/Base64Utils.h"
+
+using namespace pulsar;
+
+static const std::string clientId = "Xd23RHsUnvUlP7wchjNYOaIfazgeHd9x";
+static const std::string clientSecret = 
"rT7ps7WY8uhdVuBTKWZkttwLdQotmdEliaM5rLfmgNibvqziZ-g07ZH52N_poGAb";
+static const std::string credentialJson = R"({
+  "client_id":")" + clientId + R"(",
+  "client_secret":")" + clientSecret +
+                                          R"("
+})";
+static const std::string base64Credentials = base64::encode(credentialJson);
+static const std::string keyPath = std::tmpnam(nullptr);
+static ParamMap commonParams;
+
+static Result testCreateProducer(const std::string& privateKey);
+
+TEST(Oauth2Test, testBase64Key) {
+    ASSERT_EQ(ResultOk, testCreateProducer("data:application/json;base64," + 
base64Credentials));
+    std::string wrongCredentialsJson = 
R"({"client_id":"test-id","client_secret":"test-secret"})";
+    ASSERT_EQ(ResultAuthenticationError,
+              testCreateProducer("data:application/json;base64," + 
base64::encode(wrongCredentialsJson)));
+}
+
+TEST(Oauth2Test, testFileKey) {
+    ASSERT_EQ(ResultOk, testCreateProducer("file://" + keyPath));
+    ASSERT_EQ(ResultOk, testCreateProducer(keyPath));
+    ASSERT_EQ(ResultAuthenticationError, 
testCreateProducer("file:///tmp/file-not-exist"));
+}
+
+TEST(Oauth2Test, testWrongUrl) {
+    ASSERT_EQ(ResultAuthenticationError, 
testCreateProducer("data:text/plain;base64," + base64Credentials));
+    ASSERT_EQ(ResultAuthenticationError,
+              testCreateProducer("data:application/json;text," + 
base64Credentials));
+    ASSERT_EQ(ResultAuthenticationError, testCreateProducer("my-protocol:" + 
keyPath));
+}
+
+int main(int argc, char* argv[]) {
+    commonParams["issuer_url"] = "https://dev-kt-aa9ne.us.auth0.com";;
+    commonParams["audience"] = "https://dev-kt-aa9ne.us.auth0.com/api/v2/";;

Review Comment:
   We can put the file in `tests-conf` ahead of time without running the main 
function to generate it



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to