]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
2 | // vim: ts=8 sw=2 smarttab | |
3 | /* | |
4 | * Ceph - scalable distributed file system | |
5 | * | |
6 | * Copyright (C) 2015 New Dream Network | |
7 | * | |
8 | * This is free software; you can redistribute it and/or | |
9 | * modify it under the terms of the GNU Lesser General Public | |
10 | * License version 2.1, as published by the Free Software | |
11 | * Foundation. See file COPYING. | |
12 | * | |
13 | */ | |
14 | ||
15 | #include <stdint.h> | |
16 | #include <tuple> | |
17 | #include <iostream> | |
18 | #include <vector> | |
19 | #include <map> | |
20 | #include <random> | |
21 | ||
22 | #include "rgw/rgw_ldap.h" | |
23 | #include "rgw/rgw_token.h" | |
24 | ||
25 | #include "gtest/gtest.h" | |
26 | #include "common/ceph_argparse.h" | |
27 | #include "common/debug.h" | |
7c673cae FG |
28 | |
29 | #define dout_subsys ceph_subsys_rgw | |
30 | ||
31 | namespace { | |
32 | ||
33 | struct { | |
34 | int argc; | |
35 | char **argv; | |
36 | } saved_args; | |
37 | ||
38 | bool do_hexdump = false; | |
39 | ||
40 | string access_key("ewogICAgIlJHV19UT0tFTiI6IHsKICAgICAgICAidmVyc2lvbiI6IDEsCiAgICAgICAgInR5cGUiOiAibGRhcCIsCiAgICAgICAgImlkIjogImFkbWluIiwKICAgICAgICAia2V5IjogImxpbnV4Ym94IgogICAgfQp9Cg=="); // {admin,linuxbox} | |
41 | string other_key("ewogICAgIlJHV19UT0tFTiI6IHsKICAgICAgICAidmVyc2lvbiI6IDEsCiAgICAgICAgInR5cGUiOiAibGRhcCIsCiAgICAgICAgImlkIjogImFkbWluIiwKICAgICAgICAia2V5IjogImJhZHBhc3MiCiAgICB9Cn0K"); // {admin,badpass} | |
42 | ||
43 | string ldap_uri = "ldaps://f23-kdc.rgw.com"; | |
44 | string ldap_binddn = "uid=admin,cn=users,cn=accounts,dc=rgw,dc=com"; | |
45 | string ldap_bindpw = "supersecret"; | |
46 | string ldap_searchdn = "cn=users,cn=accounts,dc=rgw,dc=com"; | |
47 | string ldap_searchfilter = ""; | |
48 | string ldap_dnattr = "uid"; | |
49 | ||
50 | rgw::LDAPHelper ldh(ldap_uri, ldap_binddn, ldap_bindpw, ldap_searchdn, | |
51 | ldap_searchfilter, ldap_dnattr); | |
52 | ||
53 | } /* namespace */ | |
54 | ||
55 | TEST(RGW_LDAP, INIT) { | |
56 | int ret = ldh.init(); | |
57 | ASSERT_EQ(ret, 0); | |
58 | } | |
59 | ||
60 | TEST(RGW_LDAP, BIND) { | |
61 | int ret = ldh.bind(); | |
62 | ASSERT_EQ(ret, 0); | |
63 | } | |
64 | ||
65 | TEST(RGW_LDAP, AUTH) { | |
66 | using std::get; | |
67 | using namespace rgw; | |
68 | int ret = 0; | |
69 | { | |
70 | RGWToken token{from_base64(access_key)}; | |
71 | ret = ldh.auth(token.id, token.key); | |
72 | ASSERT_EQ(ret, 0); | |
73 | } | |
74 | { | |
75 | RGWToken token{from_base64(other_key)}; | |
76 | ret = ldh.auth(token.id, token.key); | |
77 | ASSERT_NE(ret, 0); | |
78 | } | |
79 | } | |
80 | ||
81 | TEST(RGW_LDAP, SHUTDOWN) { | |
82 | // nothing | |
83 | } | |
84 | ||
85 | int main(int argc, char *argv[]) | |
86 | { | |
87 | string val; | |
88 | vector<const char*> args; | |
89 | ||
90 | argv_to_vec(argc, const_cast<const char**>(argv), args); | |
91 | env_to_vec(args); | |
92 | ||
93 | for (auto arg_iter = args.begin(); arg_iter != args.end();) { | |
94 | if (ceph_argparse_witharg(args, arg_iter, &val, "--access", | |
95 | (char*) nullptr)) { | |
96 | access_key = val; | |
97 | } else if (ceph_argparse_flag(args, arg_iter, "--hexdump", | |
98 | (char*) nullptr)) { | |
99 | do_hexdump = true; | |
100 | } else { | |
101 | ++arg_iter; | |
102 | } | |
103 | } | |
104 | ||
11fdf7f2 | 105 | /* don't accidentally run as anonymous */ |
7c673cae FG |
106 | if (access_key == "") { |
107 | std::cout << argv[0] << " no AWS credentials, exiting" << std::endl; | |
108 | return EPERM; | |
109 | } | |
110 | ||
111 | saved_args.argc = argc; | |
112 | saved_args.argv = argv; | |
113 | ||
114 | ::testing::InitGoogleTest(&argc, argv); | |
115 | return RUN_ALL_TESTS(); | |
116 | } |