@@ -346,20 +346,30 @@ TEST_F(AuthorizationTest, is_auth_cache_ctrlr_enabled) {
346346 this ->authorization = std::make_unique<Authorization>(context);
347347 EXPECT_FALSE (authorization->is_auth_cache_ctrlr_enabled ());
348348}
349-
350349TEST_F (AuthorizationTest, authorize_req_websocket_disconnected) {
351- // Try to do an authorize request when the websocket is disconnected.
350+ // Test: Authorize request should return Unknown when WebSocket is offline
351+ // Setup: Explicitly disable all local authorization options
352+ this ->set_local_pre_authorize (this ->device_model , false );
353+ this ->set_local_authorize_offline (this ->device_model , false );
354+
355+ // Simulate offline WebSocket connection
352356 ON_CALL (this ->connectivity_manager , is_websocket_connected ()).WillByDefault (Return (false ));
357+
353358 const AuthorizeResponse response = authorization->authorize_req (get_id_token (), std::nullopt , std::nullopt );
354359 EXPECT_EQ (response.idTokenInfo .status , AuthorizationStatusEnum::Unknown);
355360}
356361
357362TEST_F (AuthorizationTest, authorize_req_wrong_future_message_type) {
358- // Try to do an authorize request with the websocket connected. The dispatch_call_async returns
359- // a wrong message type.
363+ // Test: Response should be Unknown if dispatch_call_async returns wrong message type
364+ // Setup: Disable local auth and simulate online WebSocket
365+ this ->set_local_pre_authorize (this ->device_model , false );
366+ this ->set_local_authorize_offline (this ->device_model , false );
367+
360368 ON_CALL (this ->connectivity_manager , is_websocket_connected ()).WillByDefault (Return (true ));
369+
361370 ocpp::EnhancedMessage<MessageType> enhanced_message;
362371 enhanced_message.messageType = MessageType::GetDisplayMessages;
372+
363373 EXPECT_CALL (mock_dispatcher, dispatch_call_async (_, _))
364374 .WillOnce (Return (std::async (std::launch::deferred, [enhanced_message]() { return enhanced_message; })));
365375
@@ -368,8 +378,13 @@ TEST_F(AuthorizationTest, authorize_req_wrong_future_message_type) {
368378}
369379
370380TEST_F (AuthorizationTest, authorize_req_accepted) {
371- // Try to do an authorize request, which is accepted.
381+ // Test: Authorize request returns Accepted when WebSocket is online and dispatcher responds positively
382+ // Setup: Disable local auth, simulate online WebSocket, and mock Accepted response
383+ this ->set_local_pre_authorize (this ->device_model , false );
384+ this ->set_local_authorize_offline (this ->device_model , false );
385+
372386 ON_CALL (this ->connectivity_manager , is_websocket_connected ()).WillByDefault (Return (true ));
387+
373388 EXPECT_CALL (mock_dispatcher, dispatch_call_async (_, _)).WillOnce (Return (std::async (std::launch::deferred, [this ]() {
374389 return create_example_authorize_response (AuthorizeCertificateStatusEnum::Accepted,
375390 AuthorizationStatusEnum::Accepted);
@@ -380,26 +395,36 @@ TEST_F(AuthorizationTest, authorize_req_accepted) {
380395}
381396
382397TEST_F (AuthorizationTest, authorize_req_exception) {
383- // Try to do an authorize request, during which which an exception is thrown.
398+ // Test: An exception in AuthorizationStatusEnum deserialization leads to Unknown response
399+ // Setup: Disable local auth, simulate online WebSocket, and mock invalid status value
400+ this ->set_local_pre_authorize (this ->device_model , false );
401+ this ->set_local_authorize_offline (this ->device_model , false );
402+
384403 ON_CALL (this ->connectivity_manager , is_websocket_connected ()).WillByDefault (Return (true ));
404+
385405 EXPECT_CALL (mock_dispatcher, dispatch_call_async (_, _)).WillOnce (Return (std::async (std::launch::deferred, [this ]() {
386- // Create authorize response with a wrong enum value, which will throw.
387- return create_example_authorize_response (AuthorizeCertificateStatusEnum::Accepted,
388- static_cast <AuthorizationStatusEnum>(INT32_MAX));
406+ return create_example_authorize_response (
407+ AuthorizeCertificateStatusEnum::Accepted,
408+ static_cast <AuthorizationStatusEnum>(INT32_MAX) // invalid value triggers exception
409+ );
389410 })));
390411
391412 const AuthorizeResponse response = authorization->authorize_req (get_id_token (), std::nullopt , std::nullopt );
392413 EXPECT_EQ (response.idTokenInfo .status , AuthorizationStatusEnum::Unknown);
393414}
394415
395416TEST_F (AuthorizationTest, authorize_req_exception2) {
396- // Try to do an authorization request, an exception is thrown for the authorize response.
417+ // Test: An exception in AuthorizeCertificateStatusEnum deserialization leads to Unknown response
418+ // Setup: Disable local auth, simulate online WebSocket, and mock invalid certificate status
419+ this ->set_local_pre_authorize (this ->device_model , false );
420+ this ->set_local_authorize_offline (this ->device_model , false );
421+
397422 ON_CALL (this ->connectivity_manager , is_websocket_connected ()).WillByDefault (Return (true ));
423+
398424 EXPECT_CALL (mock_dispatcher, dispatch_call_async (_, _)).WillOnce (Return (std::async (std::launch::deferred, [this ]() {
399- // Create authorize response with a from enum value for the authorize certificute status, which will
400- // cause an exception to be thrown.
401- return create_example_authorize_response (static_cast <AuthorizeCertificateStatusEnum>(INT32_MAX),
402- AuthorizationStatusEnum::Accepted);
425+ return create_example_authorize_response (
426+ static_cast <AuthorizeCertificateStatusEnum>(INT32_MAX), // invalid cert status
427+ AuthorizationStatusEnum::Accepted);
403428 })));
404429
405430 const AuthorizeResponse response = authorization->authorize_req (get_id_token (), std::nullopt , std::nullopt );
@@ -517,6 +542,11 @@ TEST_F(AuthorizationTest, validate_token_local_auth_list_enabled_accepted) {
517542 // Local auth list is enabled.
518543 this ->set_local_auth_list_ctrlr_enabled (this ->device_model , true );
519544
545+ // Explicit config setup for test isolation
546+ set_local_pre_authorize (false );
547+ set_local_authorize_offline (false );
548+ ON_CALL (this ->connectivity_manager , is_websocket_connected ()).WillByDefault (Return (true ));
549+
520550 IdTokenInfo id_token_info_result;
521551 id_token_info_result.status = AuthorizationStatusEnum::Accepted;
522552
@@ -540,6 +570,11 @@ TEST_F(AuthorizationTest, validate_token_local_auth_list_enabled_unknown_no_remo
540570 // Disable remote authorization.
541571 this ->disable_remote_authorization (this ->device_model , true );
542572
573+ // Explicit config setup for test isolation
574+ set_local_pre_authorize (false );
575+ set_local_authorize_offline (false );
576+ ON_CALL (this ->connectivity_manager , is_websocket_connected ()).WillByDefault (Return (true ));
577+
543578 IdTokenInfo id_token_info_result;
544579 id_token_info_result.status = AuthorizationStatusEnum::Invalid;
545580
@@ -555,14 +590,19 @@ TEST_F(AuthorizationTest, validate_token_local_auth_list_enabled_unknown_no_remo
555590}
556591
557592TEST_F (AuthorizationTest, validate_token_local_auth_list_enabled_unknown_websocket_disconnected) {
558- // Validate token with the local auth list: unknown the websocket is not connected and token info
593+ // Validate token with the local auth list: unknown because the websocket is not connected and token info
559594 // status is not accepted. Set AuthCtrlr::Enabled to true
560595 this ->set_auth_ctrlr_enabled (this ->device_model , true );
561596 // Local auth list is enabled.
562597 this ->set_local_auth_list_ctrlr_enabled (this ->device_model , true );
563598 // Remote authorization is enabled.
564599 this ->disable_remote_authorization (this ->device_model , false );
565- // But the websocket is disconnected so it is not possible to authorize the request.
600+
601+ // Explicit config setup for test isolation
602+ set_local_pre_authorize (false );
603+ set_local_authorize_offline (false );
604+
605+ // WebSocket is disconnected for this test case
566606 EXPECT_CALL (this ->connectivity_manager , is_websocket_connected ()).WillRepeatedly (Return (false ));
567607
568608 IdTokenInfo id_token_info_result;
@@ -587,7 +627,12 @@ TEST_F(AuthorizationTest, validate_token_local_auth_list_enabled_connectivity_ma
587627 this ->set_local_auth_list_ctrlr_enabled (this ->device_model , true );
588628 // Remote authorization is enabled.
589629 this ->disable_remote_authorization (this ->device_model , false );
590- // But the websocket is connected so it is possible to authorize the request.
630+
631+ // Explicit config setup for test isolation
632+ set_local_pre_authorize (false );
633+ set_local_authorize_offline (false );
634+
635+ // WebSocket is connected
591636 EXPECT_CALL (this ->connectivity_manager , is_websocket_connected ()).WillRepeatedly (Return (true ));
592637 // Authorize request returns 'Accepted'.
593638 EXPECT_CALL (mock_dispatcher, dispatch_call_async (_, _)).WillOnce (Return (std::async (std::launch::deferred, [this ]() {
@@ -658,6 +703,10 @@ TEST_F(
658703 // And offline contract validation is not allowed.
659704 this ->set_allow_contract_validation_offline (this ->device_model , true );
660705 this ->set_local_authorize_offline (this ->device_model , false );
706+
707+ // Explicit config setup for test isolation
708+ set_local_pre_authorize (false );
709+
661710 ON_CALL (this ->evse_security , verify_certificate (_, DEFAULT_LEAF_CERT_TYPE))
662711 .WillByDefault (Return (ocpp::CertificateValidationResult::Valid));
663712
@@ -681,6 +730,10 @@ TEST_F(
681730 this ->set_allow_contract_validation_offline (this ->device_model , true );
682731 this ->set_local_authorize_offline (this ->device_model , true );
683732 this ->set_local_auth_list_ctrlr_enabled (this ->device_model , true );
733+
734+ // Explicit config setup for test isolation
735+ set_local_pre_authorize (false );
736+
684737 ON_CALL (this ->evse_security , verify_certificate (_, DEFAULT_LEAF_CERT_TYPE))
685738 .WillByDefault (Return (ocpp::CertificateValidationResult::Valid));
686739
@@ -707,6 +760,10 @@ TEST_F(AuthorizationTest,
707760 // And offline contract validation is not allowed.
708761 this ->set_allow_contract_validation_offline (this ->device_model , true );
709762 this ->set_local_authorize_offline (this ->device_model , false );
763+
764+ // Explicit config setup for test isolation
765+ set_local_pre_authorize (false );
766+
710767 std::vector<ocpp::LeafCertificateType> types ({ocpp::LeafCertificateType::MO, ocpp::LeafCertificateType::V2G});
711768 ON_CALL (this ->evse_security , verify_certificate (_, types))
712769 .WillByDefault (Return (ocpp::CertificateValidationResult::Expired));
@@ -1024,6 +1081,11 @@ TEST_F(AuthorizationTest, validate_token_auth_cache_lifetime_expired) {
10241081 this ->set_auth_cache_lifetime (this ->device_model , 5000 );
10251082 // Allow remote authorization
10261083 this ->disable_remote_authorization (this ->device_model , false );
1084+
1085+ // Explicit config setup for test isolation
1086+ set_local_pre_authorize (false );
1087+ set_local_authorize_offline (false );
1088+
10271089 // The websocket is connected.
10281090 EXPECT_CALL (this ->connectivity_manager , is_websocket_connected ()).WillRepeatedly (Return (true ));
10291091
0 commit comments