KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_oauth_loopback_server.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include <boost/test/unit_test.hpp>
21
23
24
25BOOST_AUTO_TEST_SUITE( OAuthLoopbackServerTests )
26
27BOOST_AUTO_TEST_CASE( RedirectUriUsesLoopback )
28{
29 OAUTH_LOOPBACK_SERVER server( nullptr, wxS( "/oauth/callback" ), wxS( "expected-state" ) );
30
31 BOOST_REQUIRE( server.Start() );
32 BOOST_CHECK( server.GetRedirectUri().StartsWith( wxS( "http://127.0.0.1:" ) ) );
33 BOOST_CHECK( server.GetRedirectUri().EndsWith( wxS( "/oauth/callback" ) ) );
34}
35
36BOOST_AUTO_TEST_CASE( WrongStateRejected )
37{
39 wxString error;
40
42 wxS( "GET /oauth/callback?code=abc&state=wrong HTTP/1.1" ),
43 wxS( "/oauth/callback" ), wxS( "expected-state" ), response, error );
44
45 BOOST_CHECK( !ok );
46 BOOST_CHECK( error.Contains( wxString( "state" ) ) );
47}
48
49BOOST_AUTO_TEST_CASE( WrongCallbackPathRejected )
50{
52 wxString error;
53
55 wxS( "GET /wrong/path?code=abc&state=expected-state HTTP/1.1" ),
56 wxS( "/oauth/callback" ), wxS( "expected-state" ), response, error );
57
58 BOOST_CHECK( !ok );
59 BOOST_CHECK( error.Contains( wxString( "callback path" ) ) );
60}
61
62BOOST_AUTO_TEST_CASE( MissingCodeRejected )
63{
65 wxString error;
66
68 wxS( "GET /oauth/callback?state=expected-state HTTP/1.1" ),
69 wxS( "/oauth/callback" ), wxS( "expected-state" ), response, error );
70
71 BOOST_CHECK( !ok );
72 BOOST_CHECK( error.Contains( wxString( "authorization code" ) ) );
73}
74
static bool ParseAuthorizationResponse(const wxString &aRequestLine, const wxString &aExpectedPath, const wxString &aExpectedState, OAUTH_AUTHORIZATION_RESPONSE &aResponse, wxString &aError)
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(RedirectUriUsesLoopback)