From 9d5162fe102301bc94065f99a20b3067395dde2a Mon Sep 17 00:00:00 2001 From: John Spray Date: Thu, 24 Sep 2015 14:03:58 +0100 Subject: [PATCH] test/mds: add test for symbols in paths Especially, hyphens. Signed-off-by: John Spray (cherry picked from commit 4e9327f64e5965c57c0eeea397060dc2ab43cfbf) --- src/test/mds/TestMDSAuthCaps.cc | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/test/mds/TestMDSAuthCaps.cc b/src/test/mds/TestMDSAuthCaps.cc index 51ffd4688cbd0..919095d9d2fb9 100644 --- a/src/test/mds/TestMDSAuthCaps.cc +++ b/src/test/mds/TestMDSAuthCaps.cc @@ -184,6 +184,27 @@ TEST(MDSAuthCaps, AllowPath) { ASSERT_FALSE(cap.is_capable("foo", 0, 0, 0777, 0, 0, MAY_READ | MAY_WRITE, 0, 0)); } +TEST(MDSAuthCaps, AllowPathChars) { + MDSAuthCaps unquo_cap; + ASSERT_TRUE(unquo_cap.parse(g_ceph_context, "allow * path=/sandbox-._foo", NULL)); + ASSERT_FALSE(unquo_cap.allow_all()); + ASSERT_TRUE(unquo_cap.is_capable("sandbox-._foo/foo", 0, 0, 0777, 0, 0, MAY_READ | MAY_WRITE, 0, 0)); + ASSERT_FALSE(unquo_cap.is_capable("sandbox", 0, 0, 0777, 0, 0, MAY_READ | MAY_WRITE, 0, 0)); + ASSERT_FALSE(unquo_cap.is_capable("sandbox-._food", 0, 0, 0777, 0, 0, MAY_READ | MAY_WRITE, 0, 0)); + ASSERT_FALSE(unquo_cap.is_capable("foo", 0, 0, 0777, 0, 0, MAY_READ | MAY_WRITE, 0, 0)); +} + + +TEST(MDSAuthCaps, AllowPathCharsQuoted) { + MDSAuthCaps quo_cap; + ASSERT_TRUE(quo_cap.parse(g_ceph_context, "allow * path=\"/sandbox-._foo\"", NULL)); + ASSERT_FALSE(quo_cap.allow_all()); + ASSERT_TRUE(quo_cap.is_capable("sandbox-._foo/foo", 0, 0, 0777, 0, 0, MAY_READ | MAY_WRITE, 0, 0)); + ASSERT_FALSE(quo_cap.is_capable("sandbox", 0, 0, 0777, 0, 0, MAY_READ | MAY_WRITE, 0, 0)); + ASSERT_FALSE(quo_cap.is_capable("sandbox-._food", 0, 0, 0777, 0, 0, MAY_READ | MAY_WRITE, 0, 0)); + ASSERT_FALSE(quo_cap.is_capable("foo", 0, 0, 0777, 0, 0, MAY_READ | MAY_WRITE, 0, 0)); +} + TEST(MDSAuthCaps, OutputParsed) { struct CapsTest { const char *input; -- 2.39.5