aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar jboeuf <jboeuf@users.noreply.github.com>2015-12-07 10:21:36 -0800
committerGravatar jboeuf <jboeuf@users.noreply.github.com>2015-12-07 10:21:36 -0800
commit42564d1666a751a328d8f0781e7d215df4de2d05 (patch)
tree2027a292bb1a4b7d50a2e3852fcf514e815a269a
parent311af8e281bdb7b272cf15f72af5c2249d2c3727 (diff)
parentf9c8ce98cf6dd3e305087354a8a689ce6d86a442 (diff)
Merge pull request #4293 from ctiller/test-credentials-posix
Add test for grpc_get_well_known_google_credentials_file_path
-rw-r--r--test/core/security/credentials_test.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/test/core/security/credentials_test.c b/test/core/security/credentials_test.c
index b2b7cfdb6e..9af76be257 100644
--- a/test/core/security/credentials_test.c
+++ b/test/core/security/credentials_test.c
@@ -31,8 +31,10 @@
*
*/
+#include <grpc/support/port_platform.h>
#include "src/core/security/credentials.h"
+#include <stdlib.h>
#include <string.h>
#include "src/core/httpcli/httpcli.h"
@@ -1013,6 +1015,30 @@ static void test_metadata_plugin_failure(void) {
grpc_exec_ctx_finish(&exec_ctx);
}
+static void test_get_well_known_google_credentials_file_path(void) {
+#ifdef GPR_POSIX_FILE
+ char *path;
+ char *old_home = gpr_getenv("HOME");
+ gpr_setenv("HOME", "/tmp");
+ path = grpc_get_well_known_google_credentials_file_path();
+ GPR_ASSERT(path != NULL);
+ GPR_ASSERT(0 == strcmp("/tmp/.config/" GRPC_GOOGLE_CLOUD_SDK_CONFIG_DIRECTORY
+ "/" GRPC_GOOGLE_WELL_KNOWN_CREDENTIALS_FILE,
+ path));
+ gpr_free(path);
+#if defined(GPR_POSIX_ENV) || defined(GPR_LINUX_ENV)
+ unsetenv("HOME");
+ path = grpc_get_well_known_google_credentials_file_path();
+ GPR_ASSERT(path == NULL);
+#endif /* GPR_POSIX_ENV || GPR_LINUX_ENV */
+ gpr_setenv("HOME", old_home);
+#else /* GPR_POSIX_FILE */
+ char *path = grpc_get_well_known_google_credentials_file_path();
+ GPR_ASSERT(path != NULL);
+ gpr_free(path);
+#endif
+}
+
int main(int argc, char **argv) {
grpc_test_init(argc, argv);
test_empty_md_store();
@@ -1043,5 +1069,6 @@ int main(int argc, char **argv) {
test_google_default_creds_access_token();
test_metadata_plugin_success();
test_metadata_plugin_failure();
+ test_get_well_known_google_credentials_file_path();
return 0;
}