Skip to content

Commit fd19e41

Browse files
committed
Fix #1042: Add explicit config setup to remaining authorization unit tests
Signed-off-by: Stephen Oresanya <soresany@redhat.com>
1 parent b60f58a commit fd19e41

File tree

1 file changed

+56
-38
lines changed

1 file changed

+56
-38
lines changed

tests/lib/ocpp/v2/functional_blocks/test_authorization.cpp

Lines changed: 56 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -369,9 +369,7 @@ TEST_F(AuthorizationTest, authorize_req_wrong_future_message_type) {
369369
enhanced_message.messageType = MessageType::GetDisplayMessages;
370370

371371
EXPECT_CALL(mock_dispatcher, dispatch_call_async(_, _))
372-
.WillOnce(Return(std::async(std::launch::deferred, [enhanced_message]() {
373-
return enhanced_message;
374-
})));
372+
.WillOnce(Return(std::async(std::launch::deferred, [enhanced_message]() { return enhanced_message; })));
375373

376374
const AuthorizeResponse response = authorization->authorize_req(get_id_token(), std::nullopt, std::nullopt);
377375
EXPECT_EQ(response.idTokenInfo.status, AuthorizationStatusEnum::Unknown);
@@ -385,13 +383,10 @@ TEST_F(AuthorizationTest, authorize_req_accepted) {
385383

386384
ON_CALL(this->connectivity_manager, is_websocket_connected()).WillByDefault(Return(true));
387385

388-
EXPECT_CALL(mock_dispatcher, dispatch_call_async(_, _))
389-
.WillOnce(Return(std::async(std::launch::deferred, [this]() {
390-
return create_example_authorize_response(
391-
AuthorizeCertificateStatusEnum::Accepted,
392-
AuthorizationStatusEnum::Accepted
393-
);
394-
})));
386+
EXPECT_CALL(mock_dispatcher, dispatch_call_async(_, _)).WillOnce(Return(std::async(std::launch::deferred, [this]() {
387+
return create_example_authorize_response(AuthorizeCertificateStatusEnum::Accepted,
388+
AuthorizationStatusEnum::Accepted);
389+
})));
395390

396391
const AuthorizeResponse response = authorization->authorize_req(get_id_token(), std::nullopt, std::nullopt);
397392
EXPECT_EQ(response.idTokenInfo.status, AuthorizationStatusEnum::Accepted);
@@ -405,13 +400,12 @@ TEST_F(AuthorizationTest, authorize_req_exception) {
405400

406401
ON_CALL(this->connectivity_manager, is_websocket_connected()).WillByDefault(Return(true));
407402

408-
EXPECT_CALL(mock_dispatcher, dispatch_call_async(_, _))
409-
.WillOnce(Return(std::async(std::launch::deferred, [this]() {
410-
return create_example_authorize_response(
411-
AuthorizeCertificateStatusEnum::Accepted,
412-
static_cast<AuthorizationStatusEnum>(INT32_MAX) // invalid value triggers exception
413-
);
414-
})));
403+
EXPECT_CALL(mock_dispatcher, dispatch_call_async(_, _)).WillOnce(Return(std::async(std::launch::deferred, [this]() {
404+
return create_example_authorize_response(
405+
AuthorizeCertificateStatusEnum::Accepted,
406+
static_cast<AuthorizationStatusEnum>(INT32_MAX) // invalid value triggers exception
407+
);
408+
})));
415409

416410
const AuthorizeResponse response = authorization->authorize_req(get_id_token(), std::nullopt, std::nullopt);
417411
EXPECT_EQ(response.idTokenInfo.status, AuthorizationStatusEnum::Unknown);
@@ -425,28 +419,15 @@ TEST_F(AuthorizationTest, authorize_req_exception2) {
425419

426420
ON_CALL(this->connectivity_manager, is_websocket_connected()).WillByDefault(Return(true));
427421

428-
EXPECT_CALL(mock_dispatcher, dispatch_call_async(_, _))
429-
.WillOnce(Return(std::async(std::launch::deferred, [this]() {
430-
return create_example_authorize_response(
431-
static_cast<AuthorizeCertificateStatusEnum>(INT32_MAX), // invalid cert status
432-
AuthorizationStatusEnum::Accepted
433-
);
434-
})));
422+
EXPECT_CALL(mock_dispatcher, dispatch_call_async(_, _)).WillOnce(Return(std::async(std::launch::deferred, [this]() {
423+
return create_example_authorize_response(
424+
static_cast<AuthorizeCertificateStatusEnum>(INT32_MAX), // invalid cert status
425+
AuthorizationStatusEnum::Accepted);
426+
})));
435427

436428
const AuthorizeResponse response = authorization->authorize_req(get_id_token(), std::nullopt, std::nullopt);
437429
EXPECT_EQ(response.idTokenInfo.status, AuthorizationStatusEnum::Unknown);
438430
}
439-
path
440-
CMake Error at /home/soresany/everest-cmake/3rd_party/CodeCoverage.cmake:237 (message):
441-
lcov not found! Aborting...
442-
Call Stack (most recent call first):
443-
/home/soresany/everest-workspace/liblog/CMakeLists.txt:84 (setup_target_for_coverage_lcov)
444-
445-
446-
-- Configuring incomplete, errors occurred!
447-
make: *** No targets specified and no makefile found. Stop.
448-
Test project /home/soresany/everest-workspace/libocpp/build
449-
No tests were found!!!
450431

451432
TEST_F(AuthorizationTest, update_authorization_cache_size) {
452433
// Test update authorization cache size and check in the device model if the cache size is indeed updated.
@@ -559,6 +540,11 @@ TEST_F(AuthorizationTest, validate_token_local_auth_list_enabled_accepted) {
559540
// Local auth list is enabled.
560541
this->set_local_auth_list_ctrlr_enabled(this->device_model, true);
561542

543+
// Explicit config setup for test isolation
544+
set_local_pre_authorize(false);
545+
set_local_authorize_offline(false);
546+
ON_CALL(this->connectivity_manager, is_websocket_connected()).WillByDefault(Return(true));
547+
562548
IdTokenInfo id_token_info_result;
563549
id_token_info_result.status = AuthorizationStatusEnum::Accepted;
564550

@@ -582,6 +568,11 @@ TEST_F(AuthorizationTest, validate_token_local_auth_list_enabled_unknown_no_remo
582568
// Disable remote authorization.
583569
this->disable_remote_authorization(this->device_model, true);
584570

571+
// Explicit config setup for test isolation
572+
set_local_pre_authorize(false);
573+
set_local_authorize_offline(false);
574+
ON_CALL(this->connectivity_manager, is_websocket_connected()).WillByDefault(Return(true));
575+
585576
IdTokenInfo id_token_info_result;
586577
id_token_info_result.status = AuthorizationStatusEnum::Invalid;
587578

@@ -597,14 +588,19 @@ TEST_F(AuthorizationTest, validate_token_local_auth_list_enabled_unknown_no_remo
597588
}
598589

599590
TEST_F(AuthorizationTest, validate_token_local_auth_list_enabled_unknown_websocket_disconnected) {
600-
// Validate token with the local auth list: unknown the websocket is not connected and token info
591+
// Validate token with the local auth list: unknown because the websocket is not connected and token info
601592
// status is not accepted. Set AuthCtrlr::Enabled to true
602593
this->set_auth_ctrlr_enabled(this->device_model, true);
603594
// Local auth list is enabled.
604595
this->set_local_auth_list_ctrlr_enabled(this->device_model, true);
605596
// Remote authorization is enabled.
606597
this->disable_remote_authorization(this->device_model, false);
607-
// But the websocket is disconnected so it is not possible to authorize the request.
598+
599+
// Explicit config setup for test isolation
600+
set_local_pre_authorize(false);
601+
set_local_authorize_offline(false);
602+
603+
// WebSocket is disconnected for this test case
608604
EXPECT_CALL(this->connectivity_manager, is_websocket_connected()).WillRepeatedly(Return(false));
609605

610606
IdTokenInfo id_token_info_result;
@@ -629,7 +625,12 @@ TEST_F(AuthorizationTest, validate_token_local_auth_list_enabled_connectivity_ma
629625
this->set_local_auth_list_ctrlr_enabled(this->device_model, true);
630626
// Remote authorization is enabled.
631627
this->disable_remote_authorization(this->device_model, false);
632-
// But the websocket is connected so it is possible to authorize the request.
628+
629+
// Explicit config setup for test isolation
630+
set_local_pre_authorize(false);
631+
set_local_authorize_offline(false);
632+
633+
// WebSocket is connected
633634
EXPECT_CALL(this->connectivity_manager, is_websocket_connected()).WillRepeatedly(Return(true));
634635
// Authorize request returns 'Accepted'.
635636
EXPECT_CALL(mock_dispatcher, dispatch_call_async(_, _)).WillOnce(Return(std::async(std::launch::deferred, [this]() {
@@ -700,6 +701,10 @@ TEST_F(
700701
// And offline contract validation is not allowed.
701702
this->set_allow_contract_validation_offline(this->device_model, true);
702703
this->set_local_authorize_offline(this->device_model, false);
704+
705+
// Explicit config setup for test isolation
706+
set_local_pre_authorize(false);
707+
703708
ON_CALL(this->evse_security, verify_certificate(_, DEFAULT_LEAF_CERT_TYPE))
704709
.WillByDefault(Return(ocpp::CertificateValidationResult::Valid));
705710

@@ -723,6 +728,10 @@ TEST_F(
723728
this->set_allow_contract_validation_offline(this->device_model, true);
724729
this->set_local_authorize_offline(this->device_model, true);
725730
this->set_local_auth_list_ctrlr_enabled(this->device_model, true);
731+
732+
// Explicit config setup for test isolation
733+
set_local_pre_authorize(false);
734+
726735
ON_CALL(this->evse_security, verify_certificate(_, DEFAULT_LEAF_CERT_TYPE))
727736
.WillByDefault(Return(ocpp::CertificateValidationResult::Valid));
728737

@@ -749,6 +758,10 @@ TEST_F(AuthorizationTest,
749758
// And offline contract validation is not allowed.
750759
this->set_allow_contract_validation_offline(this->device_model, true);
751760
this->set_local_authorize_offline(this->device_model, false);
761+
762+
// Explicit config setup for test isolation
763+
set_local_pre_authorize(false);
764+
752765
std::vector<ocpp::LeafCertificateType> types({ocpp::LeafCertificateType::MO, ocpp::LeafCertificateType::V2G});
753766
ON_CALL(this->evse_security, verify_certificate(_, types))
754767
.WillByDefault(Return(ocpp::CertificateValidationResult::Expired));
@@ -1066,6 +1079,11 @@ TEST_F(AuthorizationTest, validate_token_auth_cache_lifetime_expired) {
10661079
this->set_auth_cache_lifetime(this->device_model, 5000);
10671080
// Allow remote authorization
10681081
this->disable_remote_authorization(this->device_model, false);
1082+
1083+
// Explicit config setup for test isolation
1084+
set_local_pre_authorize(false);
1085+
set_local_authorize_offline(false);
1086+
10691087
// The websocket is connected.
10701088
EXPECT_CALL(this->connectivity_manager, is_websocket_connected()).WillRepeatedly(Return(true));
10711089

0 commit comments

Comments
 (0)