KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_remote_provider_settings.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
22#include <json_common.h>
23
25
26
27namespace
28{
29REMOTE_PROVIDER_ENTRY makeProvider( const wxString& aId, const wxString& aUrl,
30 const wxString& aLabel = wxEmptyString,
31 const wxString& aStatus = wxEmptyString )
32{
33 REMOTE_PROVIDER_ENTRY provider;
34 provider.provider_id = aId;
35 provider.metadata_url = aUrl;
36 provider.display_name_override = aId + wxS( " display" );
37 provider.last_account_label = aLabel;
38 provider.last_auth_status = aStatus;
39 return provider;
40}
41} // namespace
42
43
44BOOST_AUTO_TEST_SUITE( RemoteProviderSettingsTests )
45
46BOOST_AUTO_TEST_CASE( MultipleProvidersRoundTrip )
47{
49 settings.providers = {
50 makeProvider( wxS( "acme" ), wxS( "https://provider.example.test/.well-known/kicad-remote-provider" ),
51 wxS( "Acme User" ), wxS( "signed_in" ) ),
52 makeProvider( wxS( "local-dev" ), wxS( "http://127.0.0.1:8080/.well-known/kicad-remote-provider" ),
53 wxS( "Local Dev" ), wxS( "signed_out" ) )
54 };
55 settings.last_used_provider_id = wxS( "local-dev" );
56 settings.destination_dir = wxS( "${KIPRJMOD}/VendorParts" );
57 settings.library_prefix = wxS( "vendor" );
58 settings.add_to_global_table = true;
59
60 nlohmann::json serialized = settings;
61 REMOTE_PROVIDER_SETTINGS roundTrip = serialized.get<REMOTE_PROVIDER_SETTINGS>();
62
63 BOOST_CHECK_EQUAL( roundTrip.providers.size(), 2 );
64 BOOST_CHECK_EQUAL( roundTrip.providers[0].provider_id, wxString( "acme" ) );
65 BOOST_CHECK_EQUAL( roundTrip.providers[1].metadata_url,
66 wxString( "http://127.0.0.1:8080/.well-known/kicad-remote-provider" ) );
67 BOOST_CHECK_EQUAL( roundTrip.last_used_provider_id, wxString( "local-dev" ) );
68 BOOST_CHECK_EQUAL( roundTrip.destination_dir, wxString( "${KIPRJMOD}/VendorParts" ) );
69 BOOST_CHECK_EQUAL( roundTrip.library_prefix, wxString( "vendor" ) );
70 BOOST_CHECK( roundTrip.add_to_global_table );
71}
72
73BOOST_AUTO_TEST_CASE( SecretsAreNotPersisted )
74{
76 settings.providers = {
77 makeProvider( wxS( "acme" ), wxS( "https://provider.example.test/.well-known/kicad-remote-provider" ),
78 wxS( "Acme User" ), wxS( "signed_in" ) )
79 };
80
81 nlohmann::json serialized = settings;
82 const std::string dumped = serialized.dump();
83
84 BOOST_CHECK_EQUAL( serialized["providers"][0]["last_account_label"].get<wxString>(),
85 wxString( "Acme User" ) );
86 BOOST_CHECK( dumped.find( "token" ) == std::string::npos );
87 BOOST_CHECK( dumped.find( "refresh" ) == std::string::npos );
88 BOOST_CHECK( dumped.find( "secret" ) == std::string::npos );
89 BOOST_CHECK( dumped.find( "user_id" ) == std::string::npos );
90}
91
92BOOST_AUTO_TEST_CASE( LastUsedProviderDefaultsAndRoundTrips )
93{
95
96 BOOST_CHECK( defaults.last_used_provider_id.IsEmpty() );
99 BOOST_CHECK( !defaults.add_to_global_table );
100
101 defaults.last_used_provider_id = wxS( "acme" );
102
103 REMOTE_PROVIDER_SETTINGS roundTrip = nlohmann::json( defaults ).get<REMOTE_PROVIDER_SETTINGS>();
104 BOOST_CHECK_EQUAL( roundTrip.last_used_provider_id, wxString( "acme" ) );
105}
106
wxString provider_id
wxString last_account_label
wxString last_auth_status
wxString display_name_override
wxString metadata_url
std::vector< REMOTE_PROVIDER_ENTRY > providers
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(MultipleProvidersRoundTrip)
BOOST_CHECK_EQUAL(result, "25.4")