-
Notifications
You must be signed in to change notification settings - Fork 35
Use Conflict Suffixes from Ciphertext Files #275
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
55a5d9f
improve extraction of ciphertext from filenames
overheadhunter bb4911b
attempt to import conflict suffix from ciphertext
overheadhunter 0426d26
apply suggestion from code review
overheadhunter 61f3706
reduce number of rename attempts + improve logging
overheadhunter 3e8dede
check existence of alternativeName file to not overwrite data
infeo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
136 changes: 136 additions & 0 deletions
136
src/test/java/org/cryptomator/cryptofs/dir/Base64UrlRegexTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,136 @@ | ||
| package org.cryptomator.cryptofs.dir; | ||
|
|
||
| import org.junit.jupiter.api.Assertions; | ||
| import org.junit.jupiter.api.Disabled; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.params.ParameterizedTest; | ||
| import org.junit.jupiter.params.provider.ValueSource; | ||
| import org.openjdk.jmh.annotations.Benchmark; | ||
| import org.openjdk.jmh.annotations.BenchmarkMode; | ||
| import org.openjdk.jmh.annotations.Fork; | ||
| import org.openjdk.jmh.annotations.Level; | ||
| import org.openjdk.jmh.annotations.Measurement; | ||
| import org.openjdk.jmh.annotations.Mode; | ||
| import org.openjdk.jmh.annotations.OutputTimeUnit; | ||
| import org.openjdk.jmh.annotations.Param; | ||
| import org.openjdk.jmh.annotations.Scope; | ||
| import org.openjdk.jmh.annotations.Setup; | ||
| import org.openjdk.jmh.annotations.State; | ||
| import org.openjdk.jmh.annotations.Warmup; | ||
| import org.openjdk.jmh.infra.Blackhole; | ||
| import org.openjdk.jmh.runner.Runner; | ||
| import org.openjdk.jmh.runner.RunnerException; | ||
| import org.openjdk.jmh.runner.options.Options; | ||
| import org.openjdk.jmh.runner.options.OptionsBuilder; | ||
|
|
||
| import java.util.concurrent.TimeUnit; | ||
| import java.util.regex.Matcher; | ||
| import java.util.regex.Pattern; | ||
|
|
||
| /** | ||
| * Needs to be compiled via maven as the JMH annotation processor needs to do stuff... | ||
| */ | ||
| public class Base64UrlRegexTest { | ||
|
|
||
| private static final String[] TEST_INPUTS = { // | ||
| "aaaaBBBBccccDDDDeeeeFFFF", | ||
| "aaaaBBBBccccDDDDeeeeFFF=", | ||
| "aaaaBBBBccccDDDDeeeeFF==", | ||
| "aaaaBBBBcc0123456789_-==", | ||
| "aaaaBBBBccccDDDDeeeeFFFFggggHH==", | ||
| "-3h6-FSsYhMCJHSAV9cjJ89F7R73b0zIB4vvO01b7uWq28fWioRagWpMv-w0MA-2ORjbShuv", // | ||
| "iJYw7QpVjKTDv_b6H5jLkauVrnPcGbV9DnIG426EBzjlYmRuJDX5cjFJLmTDA7EOEmo5rAHT3Jc=", // | ||
| "PnBpirtqhCKm9hE1341rxkqdASfyYJqNHROxR1xJWDH6TGbeqqXn_sr2Rk5zzVpSbufkiqZH9a==", // | ||
| "S8cmirjkHBHbIJZXExbFyyTOA8r6TvTPddK_sdQZpcE3RCMDI0mo9w2f53DSkqT0xRf1xcrmxvU=" // | ||
| }; | ||
|
|
||
| private static final String[] TEST_INVALID_INPUTS = { // | ||
| "aaaaBBBBccccDDDDeeee", // too short | ||
| "aaaaBBBBccccDDDDeeeeFFF", // unpadded | ||
| "====BBBBccccDDDDeeeeFFFF", // padding not at end | ||
| "????BBBBccccDDDDeeeeFFFF", // invalid chars | ||
| "conflict aaaaBBBBccccDDDDeeeeFFFF", // only a partial match | ||
| "aaaaBBBBccccDDDDeeeeFFFF conflict", // only a partial match | ||
| "-3h6-FSsYhMCJHSAV9cjJ89F7R73b0zIB4vvO01b7uWq28fWioRagWpMv-w0MA-2ORjbShu", // not multiple of four | ||
| "=iJYw7QpVjKTDv_b6H5jLkauVrnPcGbV9DnIG426EBzjlYmRuJDX5cjFJLmTDA7EOEmo5rAHT3J=", // padding in wrong position | ||
| "PnBp.irtqhCKm9hE1341rxkqdASfyYJqNHROxR1xJWDH6TGbeqqXn_sr2Rk5zzVpSbufkiqZH9a==", // invalid character | ||
| }; | ||
|
|
||
| @ParameterizedTest | ||
| @ValueSource(strings = { | ||
| "([a-zA-Z0-9-_]{4})*[a-zA-Z0-9-_]{20}[a-zA-Z0-9-_=]{4}", | ||
| "[a-zA-Z0-9-_]{20}([a-zA-Z0-9-_]{4})*[a-zA-Z0-9-_=]{4}", | ||
| "[a-zA-Z0-9-_]{20}([a-zA-Z0-9-_]{4})*[a-zA-Z0-9-_=]{4}", | ||
| "[a-zA-Z0-9-_]{20}(?:[a-zA-Z0-9-_]{4})*[a-zA-Z0-9-_=]{4}", | ||
| "[a-zA-Z0-9-_]{20}(?:[a-zA-Z0-9-_]{4})*(?:[a-zA-Z0-9-_]{4}|[a-zA-Z0-9-_]{3}=|[a-zA-Z0-9-_]{2}==)", // most strict | ||
| "[a-zA-Z0-9-_]{20}(?:[a-zA-Z0-9-_=]{4})+", // most permissive | ||
| }) | ||
| public void testValidBase64Pattern(String patternString) { | ||
| Pattern pattern = Pattern.compile(patternString); | ||
| for (String input : TEST_INPUTS) { | ||
| Matcher matcher = pattern.matcher(input); | ||
| Assertions.assertTrue(matcher.matches(), "pattern does not match " + input); | ||
| } | ||
| } | ||
|
|
||
| @ParameterizedTest | ||
| @ValueSource(strings = { | ||
| "([a-zA-Z0-9-_]{4})*[a-zA-Z0-9-_]{20}[a-zA-Z0-9-_=]{4}", | ||
| "[a-zA-Z0-9-_]{20}([a-zA-Z0-9-_]{4})*[a-zA-Z0-9-_=]{4}", | ||
| "[a-zA-Z0-9-_]{20}([a-zA-Z0-9-_]{4})*[a-zA-Z0-9-_=]{4}", | ||
| "[a-zA-Z0-9-_]{20}(?:[a-zA-Z0-9-_]{4})*[a-zA-Z0-9-_=]{4}", | ||
| "[a-zA-Z0-9-_]{20}(?:[a-zA-Z0-9-_]{4})*(?:[a-zA-Z0-9-_]{4}|[a-zA-Z0-9-_]{3}=|[a-zA-Z0-9-_]{2}==)", // most strict | ||
| "[a-zA-Z0-9-_]{20}(?:[a-zA-Z0-9-_=]{4})+", // most permissive | ||
| }) | ||
| public void testInvalidInputs(String patternString) { | ||
| Pattern pattern = Pattern.compile(patternString); | ||
| for (String input : TEST_INVALID_INPUTS) { | ||
| Matcher matcher = pattern.matcher(input); | ||
| Assertions.assertFalse(matcher.matches(), "pattern matches " + input); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| @Disabled // only run manually | ||
| public void runBenchmarks() throws RunnerException { | ||
| // Taken from http://stackoverflow.com/a/30486197/4014509: | ||
| Options opt = new OptionsBuilder().include(RegexBenchmark.class.getSimpleName()).build(); | ||
| new Runner(opt).run(); | ||
| } | ||
|
|
||
| @State(Scope.Thread) | ||
| @Fork(3) | ||
| @Warmup(iterations = 2, time = 500, timeUnit = TimeUnit.MILLISECONDS) | ||
| @Measurement(iterations = 3, time = 500, timeUnit = TimeUnit.MILLISECONDS) | ||
| @BenchmarkMode(value = {Mode.AverageTime}) | ||
| @OutputTimeUnit(TimeUnit.MICROSECONDS) | ||
| public static class RegexBenchmark { | ||
|
|
||
| // Base64 regex pattern | ||
| @Param({ | ||
| "([a-zA-Z0-9-_]{4})*[a-zA-Z0-9-_]{20}[a-zA-Z0-9-_=]{4}", | ||
| "[a-zA-Z0-9-_]{20}([a-zA-Z0-9-_]{4})*[a-zA-Z0-9-_=]{4}", | ||
| "[a-zA-Z0-9-_]{20}([a-zA-Z0-9-_]{4})*[a-zA-Z0-9-_=]{4}", | ||
| "[a-zA-Z0-9-_]{20}(?:[a-zA-Z0-9-_]{4})*[a-zA-Z0-9-_=]{4}", | ||
| "[a-zA-Z0-9-_]{20}(?:[a-zA-Z0-9-_]{4})*(?:[a-zA-Z0-9-_]{4}|[a-zA-Z0-9-_]{3}=|[a-zA-Z0-9-_]{2}==)", // most strict | ||
| "[a-zA-Z0-9-_]{20}(?:[a-zA-Z0-9-_=]{4})+", // most permissive | ||
| }) | ||
| private String patternString; | ||
|
|
||
| private Pattern pattern; | ||
|
|
||
| @Setup(Level.Trial) | ||
| public void compilePattern() { | ||
| pattern = Pattern.compile(patternString); | ||
| } | ||
|
|
||
| @Benchmark | ||
| public void testPattern(Blackhole bh) { | ||
| for (String input : TEST_INPUTS) { | ||
| Matcher matcher = pattern.matcher(input); | ||
| bh.consume(matcher.matches()); | ||
| } | ||
| } | ||
|
|
||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.