aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Craig Tiller <ctiller@google.com>2015-12-07 08:21:57 -0800
committerGravatar Craig Tiller <ctiller@google.com>2015-12-07 08:21:57 -0800
commitf9c8ce98cf6dd3e305087354a8a689ce6d86a442 (patch)
tree53fa534f21e345f474e8fdc91d3a9a16dfb34040
parentb67ef24d776fcc2a0b75ca4c85f58be762d0c68d (diff)
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;
}