]>
git.proxmox.com Git - ceph.git/blob - ceph/src/test/test_rgw_ldap.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2015 New Dream Network
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.
22 #include "rgw/rgw_ldap.h"
23 #include "rgw/rgw_token.h"
25 #include "gtest/gtest.h"
26 #include "common/ceph_argparse.h"
27 #include "common/debug.h"
29 #define dout_subsys ceph_subsys_rgw
40 bool do_hexdump
= false;
42 string
access_key("ewogICAgIlJHV19UT0tFTiI6IHsKICAgICAgICAidmVyc2lvbiI6IDEsCiAgICAgICAgInR5cGUiOiAibGRhcCIsCiAgICAgICAgImlkIjogImFkbWluIiwKICAgICAgICAia2V5IjogImxpbnV4Ym94IgogICAgfQp9Cg=="); // {admin,linuxbox}
43 string
other_key("ewogICAgIlJHV19UT0tFTiI6IHsKICAgICAgICAidmVyc2lvbiI6IDEsCiAgICAgICAgInR5cGUiOiAibGRhcCIsCiAgICAgICAgImlkIjogImFkbWluIiwKICAgICAgICAia2V5IjogImJhZHBhc3MiCiAgICB9Cn0K"); // {admin,badpass}
45 string ldap_uri
= "ldaps://f23-kdc.rgw.com";
46 string ldap_binddn
= "uid=admin,cn=users,cn=accounts,dc=rgw,dc=com";
47 string ldap_bindpw
= "supersecret";
48 string ldap_searchdn
= "cn=users,cn=accounts,dc=rgw,dc=com";
49 string ldap_searchfilter
= "";
50 string ldap_dnattr
= "uid";
52 rgw::LDAPHelper
ldh(ldap_uri
, ldap_binddn
, ldap_bindpw
, ldap_searchdn
,
53 ldap_searchfilter
, ldap_dnattr
);
57 TEST(RGW_LDAP
, INIT
) {
62 TEST(RGW_LDAP
, BIND
) {
67 TEST(RGW_LDAP
, AUTH
) {
72 RGWToken token
{from_base64(access_key
)};
73 ret
= ldh
.auth(token
.id
, token
.key
);
77 RGWToken token
{from_base64(other_key
)};
78 ret
= ldh
.auth(token
.id
, token
.key
);
83 TEST(RGW_LDAP
, SHUTDOWN
) {
87 int main(int argc
, char *argv
[])
89 auto args
= argv_to_vec(argc
, argv
);
93 for (auto arg_iter
= args
.begin(); arg_iter
!= args
.end();) {
94 if (ceph_argparse_witharg(args
, arg_iter
, &val
, "--access",
97 } else if (ceph_argparse_flag(args
, arg_iter
, "--hexdump",
105 /* don't accidentally run as anonymous */
106 if (access_key
== "") {
107 std::cout
<< argv
[0] << " no AWS credentials, exiting" << std::endl
;
111 saved_args
.argc
= argc
;
112 saved_args
.argv
= argv
;
114 ::testing::InitGoogleTest(&argc
, argv
);
115 return RUN_ALL_TESTS();