diff options
author | Jan Holesovsky <kendy@collabora.com> | 2017-08-16 16:38:00 +0200 |
---|---|---|
committer | Jan Holesovsky <kendy@collabora.com> | 2017-08-17 13:40:57 +0200 |
commit | afcfac4bef95cf7800effbc90818a0bfb8b434c2 (patch) | |
tree | cf8c23059d54848bdc26265d3cea372ae97fd7cb /test | |
parent | 8a02d9eace04407709567c298b6e12542eceb223 (diff) |
access_header: Infrastructure for providing custom headers for authentication.
Change-Id: I52e61dc01dbad0d501471e663aaf364d9bc23c52
Reviewed-on: https://gerrit.libreoffice.org/41223
Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
Reviewed-by: pranavk <pranavk@collabora.co.uk>
Tested-by: pranavk <pranavk@collabora.co.uk>
Diffstat (limited to 'test')
-rw-r--r-- | test/Makefile.am | 1 | ||||
-rw-r--r-- | test/WhiteBoxTests.cpp | 45 |
2 files changed, 46 insertions, 0 deletions
diff --git a/test/Makefile.am b/test/Makefile.am index 9ff9bb447..5f7b769d0 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -37,6 +37,7 @@ wsd_sources = \ ../common/Util.cpp \ ../common/MessageQueue.cpp \ ../kit/Kit.cpp \ + ../wsd/Auth.cpp \ ../wsd/TileCache.cpp \ ../wsd/TestStubs.cpp \ ../common/Unit.cpp \ diff --git a/test/WhiteBoxTests.cpp b/test/WhiteBoxTests.cpp index 7079c60af..adab5ed0c 100644 --- a/test/WhiteBoxTests.cpp +++ b/test/WhiteBoxTests.cpp @@ -11,6 +11,7 @@ #include <cppunit/extensions/HelperMacros.h> +#include <Auth.hpp> #include <ChildSession.hpp> #include <Common.hpp> #include <Kit.hpp> @@ -32,6 +33,7 @@ class WhiteBoxTests : public CPPUNIT_NS::TestFixture CPPUNIT_TEST(testRegexListMatcher_Init); CPPUNIT_TEST(testEmptyCellCursor); CPPUNIT_TEST(testRectanglesIntersect); + CPPUNIT_TEST(testAuthorization); CPPUNIT_TEST_SUITE_END(); @@ -43,6 +45,7 @@ class WhiteBoxTests : public CPPUNIT_NS::TestFixture void testRegexListMatcher_Init(); void testEmptyCellCursor(); void testRectanglesIntersect(); + void testAuthorization(); }; void WhiteBoxTests::testLOOLProtocolFunctions() @@ -419,6 +422,48 @@ void WhiteBoxTests::testRectanglesIntersect() 1000, 1000, 2000, 1000)); } +void WhiteBoxTests::testAuthorization() +{ + Authorization auth1(Authorization::Type::Token, "abc"); + Poco::URI uri1("http://localhost"); + auth1.authorizeURI(uri1); + CPPUNIT_ASSERT_EQUAL(uri1.toString(), std::string("http://localhost/?access_token=abc")); + Poco::Net::HTTPRequest req1; + auth1.authorizeRequest(req1); + CPPUNIT_ASSERT_EQUAL(req1.get("Authorization"), std::string("Bearer abc")); + + Authorization auth1modify(Authorization::Type::Token, "modified"); + // still the same uri1, currently "http://localhost/?access_token=abc" + auth1modify.authorizeURI(uri1); + CPPUNIT_ASSERT_EQUAL(uri1.toString(), std::string("http://localhost/?access_token=modified")); + + Authorization auth2(Authorization::Type::Header, "def"); + Poco::Net::HTTPRequest req2; + auth2.authorizeRequest(req2); + CPPUNIT_ASSERT(!req2.has("Authorization")); + + Authorization auth3(Authorization::Type::Header, "Authorization: Basic huhu== "); + Poco::URI uri2("http://localhost"); + auth3.authorizeURI(uri2); + // nothing added with the Authorization header approach + CPPUNIT_ASSERT_EQUAL(uri2.toString(), std::string("http://localhost")); + Poco::Net::HTTPRequest req3; + auth3.authorizeRequest(req3); + CPPUNIT_ASSERT_EQUAL(req3.get("Authorization"), std::string("Basic huhu==")); + + Authorization auth4(Authorization::Type::Header, " Authorization: Basic blah== \n\r X-Something: additional "); + Poco::Net::HTTPRequest req4; + auth4.authorizeRequest(req4); + CPPUNIT_ASSERT_EQUAL(req4.get("Authorization"), std::string("Basic blah==")); + CPPUNIT_ASSERT_EQUAL(req4.get("X-Something"), std::string("additional")); + + Authorization auth5(Authorization::Type::Header, " Authorization: Basic huh== \n\r X-Something-More: else \n\r"); + Poco::Net::HTTPRequest req5; + auth5.authorizeRequest(req5); + CPPUNIT_ASSERT_EQUAL(req5.get("Authorization"), std::string("Basic huh==")); + CPPUNIT_ASSERT_EQUAL(req5.get("X-Something-More"), std::string("else")); +} + CPPUNIT_TEST_SUITE_REGISTRATION(WhiteBoxTests); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |