Skip to content

Change data structure HashMap to LinkedHashMap to fix flaky test#1

Open
219sansim wants to merge 1 commit into
mainfrom
fix-flaky-hashmap
Open

Change data structure HashMap to LinkedHashMap to fix flaky test#1
219sansim wants to merge 1 commit into
mainfrom
fix-flaky-hashmap

Conversation

@219sansim

Copy link
Copy Markdown
Owner

Summary:

This the fix for the flaky test case

com.eatthepath.pushy.apns.server.TokenAuthenticationValidatingPushNotificationHandlerTest.testHandleNotificationWithWithExpiredAuthenticationToken

This test is detected as flaky by the NonDex tool developed by researchers at UIUC. (https://github.com/TestingResearchIllinois/NonDex)

Flaky tests are tests in software development that produce inconsistent or unreliable results, which can lead to false non-deterministic outcomes of the test case, fixing them is important to both reliable testing and fixing vulnerabilities in the code.

The outcomes of the TokenAuthenticationValidatingPushNotificationHandler are sometimes INVALID_PROVIDER_TOKEN instead of EXPIRED_PROVIDER_TOKEN which is why the assert fails
This is because the verifySignature method fails before reaching the line of code which detects an EXPIRED_PROVIDER_TOKEN

The verifySignature method in AuthenticationToken class converts headerJson and clainsJson to hashmap and then to string in order for token authentication. The elements in the hashmap are not guaranteed to be in the same order always which introduces a vulnerability in the code, however elements in a LinkedHashmap are guaranteed to be stored in a particular order. The authentication may fail and result in INVALID_PROVIDER_TOKEN even if it is correct.

Fix: Use LinkedHashMap instead HashMap

Tests Plan:

mvn -pl pushy edu.illinois:nondex-maven-plugin:2.1.1:nondex Dtest=com.eatthepath.pushy.apns.server.TokenAuthenticationValidatingPushNotificationHandlerTest#testHandleNotificationWithWithExpiredAuthenticationToken

@219sansim

Copy link
Copy Markdown
Owner Author

When I run mvn -pl pushy edu.illinois:nondex-maven-plugin:2.1.1:nondex the following tests fail

  1. com.eatthepath.pushy.apns.ApnsClientTest#testSendNotification
  2. com.eatthepath.pushy.apns.ApnsClientTest#testSendNotificationWithPushTypeHeader
  3. com.eatthepath.pushy.apns.server.TokenAuthenticationValidatingPushNotificationHandlerTest#testHandleNotificationWithEmptyPayload
  4. com.eatthepath.pushy.apns.server.TokenAuthenticationValidatingPushNotificationHandlerTest#testHandleNotificationWithCollapseId
  5. com.eatthepath.pushy.apns.server.TokenAuthenticationValidatingPushNotificationHandlerTest#testHandleNotificationWithExpirationDate
  6. com.eatthepath.pushy.apns.server.TokenAuthenticationValidatingPushNotificationHandlerTest#testHandleNotificationWithSpecifiedPriority
  7. com.eatthepath.pushy.apns.server.TokenAuthenticationValidatingPushNotificationHandlerTest#testHandleNotificationWithMissingPayload
  8. com.eatthepath.pushy.apns.server.TokenAuthenticationValidatingPushNotificationHandlerTest#testHandleNotificationWithOversizedPayload
  9. com.eatthepath.pushy.apns.server.TokenAuthenticationValidatingPushNotificationHandlerTest#testHandleNotificationWithValidNotification
  10. com.eatthepath.pushy.apns.server.TokenAuthenticationValidatingPushNotificationHandlerTest#testHandleNotificationWithWithTokenForWrongTopic
  11. com.eatthepath.pushy.apns.server.TokenAuthenticationValidatingPushNotificationHandlerTest#testHandleNotificationWithWithExpiredAuthenticationToken
  12. com.eatthepath.pushy.apns.auth.AuthenticationTokenTest#testVerifySignature

All the tests pass with the same fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant