Пример #1
0
        public static async Task RunJwtTokenCredsAsync(TestService.TestServiceClient client)
        {
            Console.WriteLine("running jwt_token_creds");
            var credential = await GoogleCredential.GetApplicationDefaultAsync();

            // check this a credential with scope support, but don't add the scope.
            Assert.IsTrue(credential.IsCreateScopedRequired);
            client.HeaderInterceptor = OAuth2Interceptors.FromCredential(credential);

            var request = SimpleRequest.CreateBuilder()
                          .SetResponseType(PayloadType.COMPRESSABLE)
                          .SetResponseSize(314159)
                          .SetPayload(CreateZerosPayload(271828))
                          .SetFillUsername(true)
                          .SetFillOauthScope(true)
                          .Build();

            var response = client.UnaryCall(request);

            Assert.AreEqual(PayloadType.COMPRESSABLE, response.Payload.Type);
            Assert.AreEqual(314159, response.Payload.Body.Length);
            Assert.AreEqual(ServiceAccountUser, response.Username);
            Console.WriteLine("Passed!");
        }
Пример #2
0
        public static async Task RunComputeEngineCredsAsync(TestService.TestServiceClient client)
        {
            Console.WriteLine("running compute_engine_creds");
            var credential = await GoogleCredential.GetApplicationDefaultAsync();

            Assert.IsFalse(credential.IsCreateScopedRequired);
            client.HeaderInterceptor = OAuth2Interceptors.FromCredential(credential);

            var request = SimpleRequest.CreateBuilder()
                          .SetResponseType(PayloadType.COMPRESSABLE)
                          .SetResponseSize(314159)
                          .SetPayload(CreateZerosPayload(271828))
                          .SetFillUsername(true)
                          .SetFillOauthScope(true)
                          .Build();

            var response = client.UnaryCall(request);

            Assert.AreEqual(PayloadType.COMPRESSABLE, response.Payload.Type);
            Assert.AreEqual(314159, response.Payload.Body.Length);
            Assert.AreEqual(AuthScopeResponse, response.OauthScope);
            Assert.AreEqual(ComputeEngineUser, response.Username);
            Console.WriteLine("Passed!");
        }