From 21ec6c30b130ef5278eb78dcee2524db7af816a9 Mon Sep 17 00:00:00 2001
From: murgatroid99 <mlumish@google.com>
Date: Mon, 20 Jul 2015 17:59:25 -0700
Subject: [PATCH] Added oauth2_auth_token and per_rpc_creds Node interop tests

---
 src/node/interop/interop_client.js | 56 +++++++++++++++++++++++++++++-
 1 file changed, 55 insertions(+), 1 deletion(-)

diff --git a/src/node/interop/interop_client.js b/src/node/interop/interop_client.js
index b61b0b63c0..0aadd862e5 100644
--- a/src/node/interop/interop_client.js
+++ b/src/node/interop/interop_client.js
@@ -318,6 +318,58 @@ function authTest(expected_user, scope, client, done) {
   });
 }
 
+function oauth2Test(expected_user, scope, per_rpc, client, done) {
+  (new GoogleAuth()).getApplicationDefault(function(err, credential) {
+    assert.ifError(err);
+    var arg = {
+      response_type: 'COMPRESSABLE',
+      response_size: 314159,
+      payload: {
+        body: zeroBuffer(271828)
+      },
+      fill_username: true,
+      fill_oauth_scope: true
+    };
+    credential = credential.createScoped(scope);
+    credential.getAccessToken(function(err, token) {
+      assert.ifError(err);
+      var updateMetadata = function(authURI, metadata, callback) {
+        metadata = _.clone(metadata);
+        if (metadata.Authorization) {
+          metadata.Authorization = _.clone(metadata.Authorization);
+        } else {
+          metadata.Authorization = [];
+        }
+        metadata.Authorization.push('Bearer ' + token);
+        callback(null, metadata);
+      };
+      var makeTestCall = function(error, client_metadata) {
+        assert.ifError(error);
+        var call = client.unaryCall(arg, function(err, resp) {
+          assert.ifError(err);
+          assert.strictEqual(resp.payload.type, 'COMPRESSABLE');
+          assert.strictEqual(resp.payload.body.length, 314159);
+          assert.strictEqual(resp.username, expected_user);
+          assert.strictEqual(resp.oauth_scope, AUTH_SCOPE_RESPONSE);
+        });
+        call.on('status', function(status) {
+          assert.strictEqual(status.code, grpc.status.OK);
+          if (done) {
+            done();
+          }
+        });
+      };
+      if (per_rpc) {
+        updateMetadata('', {}, makeTestCall);
+      } else {
+        client.updateMetadata = updateMetadata;
+        makeTestCall(null, {});
+      }
+
+    });
+  });
+}
+
 /**
  * Map from test case names to test functions
  */
@@ -333,7 +385,9 @@ var test_cases = {
   timeout_on_sleeping_server: timeoutOnSleepingServer,
   compute_engine_creds: _.partial(authTest, COMPUTE_ENGINE_USER, null),
   service_account_creds: _.partial(authTest, AUTH_USER, AUTH_SCOPE),
-  jwt_token_creds: _.partial(authTest, AUTH_USER, null)
+  jwt_token_creds: _.partial(authTest, AUTH_USER, null),
+  oauth2_auth_token: _.partial(oauth2Test, AUTH_USER, AUTH_SCOPE, false),
+  per_rpc_creds: _.partial(oauth2Test, AUTH_USER, AUTH_SCOPE, true)
 };
 
 /**
-- 
GitLab