~ubuntu-branches/ubuntu/gutsy/poco/gutsy

« back to all changes in this revision

Viewing changes to Net/testsuite/src/HTTPCredentialsTest.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Krzysztof Burghardt
  • Date: 2007-04-27 18:33:48 UTC
  • Revision ID: james.westby@ubuntu.com-20070427183348-xgnpct0qd6a2ip34
Tags: upstream-1.2.9
ImportĀ upstreamĀ versionĀ 1.2.9

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// HTTPCredentialsTest.cpp
 
3
//
 
4
// $Id: //poco/1.2/Net/testsuite/src/HTTPCredentialsTest.cpp#1 $
 
5
//
 
6
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
 
7
// and Contributors.
 
8
//
 
9
// Permission is hereby granted, free of charge, to any person or organization
 
10
// obtaining a copy of the software and accompanying documentation covered by
 
11
// this license (the "Software") to use, reproduce, display, distribute,
 
12
// execute, and transmit the Software, and to prepare derivative works of the
 
13
// Software, and to permit third-parties to whom the Software is furnished to
 
14
// do so, all subject to the following:
 
15
// 
 
16
// The copyright notices in the Software and this entire statement, including
 
17
// the above license grant, this restriction and the following disclaimer,
 
18
// must be included in all copies of the Software, in whole or in part, and
 
19
// all derivative works of the Software, unless such copies or derivative
 
20
// works are solely in the form of machine-executable object code generated by
 
21
// a source language processor.
 
22
// 
 
23
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
24
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
25
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
 
26
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
 
27
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
 
28
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 
29
// DEALINGS IN THE SOFTWARE.
 
30
//
 
31
 
 
32
 
 
33
#include "HTTPCredentialsTest.h"
 
34
#include "CppUnit/TestCaller.h"
 
35
#include "CppUnit/TestSuite.h"
 
36
#include "Poco/Net/HTTPRequest.h"
 
37
#include "Poco/Net/HTTPBasicCredentials.h"
 
38
#include "Poco/Net/NetException.h"
 
39
 
 
40
 
 
41
using Poco::Net::HTTPRequest;
 
42
using Poco::Net::HTTPBasicCredentials;
 
43
using Poco::Net::NotAuthenticatedException;
 
44
 
 
45
 
 
46
HTTPCredentialsTest::HTTPCredentialsTest(const std::string& name): CppUnit::TestCase(name)
 
47
{
 
48
}
 
49
 
 
50
 
 
51
HTTPCredentialsTest::~HTTPCredentialsTest()
 
52
{
 
53
}
 
54
 
 
55
 
 
56
void HTTPCredentialsTest::testCredentials()
 
57
{
 
58
        HTTPRequest request;
 
59
        assert (!request.hasCredentials());
 
60
        
 
61
        HTTPBasicCredentials cred("user", "secret");
 
62
        cred.authenticate(request);
 
63
        assert (request.hasCredentials());
 
64
        std::string scheme;
 
65
        std::string info;
 
66
        request.getCredentials(scheme, info);
 
67
        assert (scheme == "Basic");
 
68
        assert (info == "dXNlcjpzZWNyZXQ=");
 
69
        
 
70
        HTTPBasicCredentials cred2(request);
 
71
        assert (cred2.getUsername() == "user");
 
72
        assert (cred2.getPassword() == "secret");
 
73
}
 
74
 
 
75
 
 
76
void HTTPCredentialsTest::testBadCredentials()
 
77
{
 
78
        HTTPRequest request;
 
79
        
 
80
        std::string scheme;
 
81
        std::string info;
 
82
        try
 
83
        {
 
84
                request.getCredentials(scheme, info);
 
85
                fail("no credentials - must throw");
 
86
        }
 
87
        catch (NotAuthenticatedException&)
 
88
        {
 
89
        }
 
90
        
 
91
        request.setCredentials("Test", "SomeData");
 
92
        request.getCredentials(scheme, info);
 
93
        assert (scheme == "Test");
 
94
        assert (info == "SomeData");
 
95
        
 
96
        try
 
97
        {
 
98
                HTTPBasicCredentials cred(request);
 
99
                fail("bad scheme - must throw");
 
100
        }
 
101
        catch (NotAuthenticatedException&)
 
102
        {
 
103
        }
 
104
}
 
105
 
 
106
 
 
107
void HTTPCredentialsTest::setUp()
 
108
{
 
109
}
 
110
 
 
111
 
 
112
void HTTPCredentialsTest::tearDown()
 
113
{
 
114
}
 
115
 
 
116
 
 
117
CppUnit::Test* HTTPCredentialsTest::suite()
 
118
{
 
119
        CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("HTTPCredentialsTest");
 
120
 
 
121
        CppUnit_addTest(pSuite, HTTPCredentialsTest, testCredentials);
 
122
        CppUnit_addTest(pSuite, HTTPCredentialsTest, testBadCredentials);
 
123
 
 
124
        return pSuite;
 
125
}