Skip to content

Commit

Permalink
[FOUNDATION-102] hash source string if its length greater than 255 ch…
Browse files Browse the repository at this point in the history
…aracters
  • Loading branch information
mujeebul authored Aug 4, 2021
1 parent c7d2df2 commit 60b7c17
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.compass.vinyl.Scenario;
import com.compass.vinyl.ScenarioMetadata;
import com.compass.vinyl.serializer.Serializer;
import com.compass.vinyl.utils.Utilities;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -34,6 +35,8 @@ public class LocalFileSystemRecordPlayer implements RecordPlayer {

private static final String VINYL_EXTENSION = ".vinyl";

private static final int MAX_SOURCE_LENGTH = 255;

@Override
public boolean record(Scenario scenario, RecordingConfig config) {
String filePath = getFilePath(scenario, config);
Expand Down Expand Up @@ -181,9 +184,12 @@ public void deleteByTags(List<String> tags, RecordingConfig config) {
}

private String getFilePath(Scenario scenario, RecordingConfig config) {
String path = config.getRecordingPath();
return path + File.separator
+ normalizeName(scenario.getSource()) + File.separator + normalizeName(scenario.getMethod());
String basePath = config.getRecordingPath();
String source = scenario.getSource();
if (scenario.getSource().length() > MAX_SOURCE_LENGTH) {
source = Utilities.md5(normalizeName(scenario.getSource()));
}
return basePath + File.separator + source + File.separator + normalizeName(scenario.getMethod());
}

private String normalizeName(String filename) {
Expand Down
18 changes: 18 additions & 0 deletions src/test/java/com/compass/vinyl/player/RecordPlayerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,22 @@ public void deleteByTags() {
Scenario scenario = player.playback(expectedScenario, config);
Assertions.assertNull(scenario, "Scenario doesn't exist but result is not null.");
}

@Test
@Order(4)
public void recordLongSource() {
String source = "_api_v3_collaboration_team_application_wildcard_optin__json__7B_22application_22_3A22_2C_22enrichOptions_22_3A_5B0_5D_2C_22isMobileApp_22_3Atrue_2C_22resource_22_3A11_2C_22teamId_22_3A_225ef9b6de5af34d0001372667_22_2C_22userId_22_3A_225ef9b16d25686d00012bd909_22_7D";

Scenario scenario = new Scenario(source, "test",
Arrays.asList(new Data("bird", "any_bird")), new Data("animal", "any_animal"));

boolean status = player.record(scenario, config);
Assertions.assertTrue(status, "Recording of the scenario failed for long string.");

source = "_api_v3_collaboration_team_application_wildcard_optin";
scenario = new Scenario(source, "test",
Arrays.asList(new Data("bird", "any_bird")), new Data("animal", "any_animal"));
status = player.record(scenario, config);
Assertions.assertTrue(status, "Recording of the scenario failed.");
}
}

0 comments on commit 60b7c17

Please sign in to comment.