Skip to content

Commit

Permalink
Merge pull request #1756 in ITERATE/cyberduck from bugfix/TRAC-10750 …
Browse files Browse the repository at this point in the history
…to master

* commit 'effd4386e29e87ba58856b92d2ad93ae6eb0990c':
  Hash code collision with same path length and common prefix. Test with actual string comparision. Fix #10750.
  Add test.
  Review.
  Add failing test
  • Loading branch information
automerge committed Aug 20, 2019
2 parents 0770c9e + effd438 commit 1cbf7e3
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
Expand Up @@ -50,7 +50,8 @@ public int hashCode() {

@Override
public boolean test(final Path test) {
return this.hashCode() == new SimplePathPredicate(test).hashCode();
return type.equals(test.isSymbolicLink() ? Path.Type.symboliclink : test.isFile() ? Path.Type.file : Path.Type.directory)
&& path.equals(normalizer.normalize(test.getAbsolute()).toString());
}

@Override
Expand Down
Expand Up @@ -27,8 +27,14 @@ public class SimplePathPredicateTest {
@Test
public void testPredicateTest() {
final Path t = new Path("/f", EnumSet.of(Path.Type.file));
assertTrue(new SimplePathPredicate(t).test(t));
assertTrue(new SimplePathPredicate(t).test(new Path("/f", EnumSet.of(Path.Type.file))));
assertFalse(new SimplePathPredicate(t).test(new Path("/f/a", EnumSet.of(Path.Type.file))));
assertFalse(new SimplePathPredicate(t).test(new Path("/f", EnumSet.of(Path.Type.directory))));
}

@Test
public void testCollision() {
final Path t = new Path("/d/2R", EnumSet.of(Path.Type.directory));
assertFalse(new SimplePathPredicate(t).test(new Path("/d/33", EnumSet.of(Path.Type.directory))));
}
}
@@ -0,0 +1,40 @@
package ch.cyberduck.core.onedrive;

import ch.cyberduck.core.DisabledListProgressListener;
import ch.cyberduck.core.Path;
import ch.cyberduck.core.features.Directory;
import ch.cyberduck.core.features.IdProvider;
import ch.cyberduck.core.onedrive.features.GraphDirectoryFeature;
import ch.cyberduck.core.onedrive.features.GraphFileIdProvider;
import ch.cyberduck.core.transfer.TransferStatus;
import ch.cyberduck.test.IntegrationTest;

import org.junit.Test;
import org.junit.experimental.categories.Category;

import java.util.EnumSet;

import static org.junit.Assert.*;

@Category(IntegrationTest.class)
public class GraphFileIdProviderTest extends AbstractOneDriveTest {

@Test
public void testFileIdCollision() throws Exception {
final Path path2R = new Path("/2R", EnumSet.of(Path.Type.directory));
final Path path33 = new Path("/33", EnumSet.of(Path.Type.directory));

final Directory directoryFeature = new GraphDirectoryFeature(session);
final Path path2RWithId = directoryFeature.mkdir(path2R, null, new TransferStatus());
assertNotNull(path2RWithId.attributes().getVersionId());
final Path path33WithId = directoryFeature.mkdir(path33, null, new TransferStatus());
assertNotNull(path33WithId.attributes().getVersionId());
assertNotEquals(path2RWithId.attributes().getVersionId(), path33WithId.attributes().getVersionId());

final IdProvider idProvider = new GraphFileIdProvider(session);
final String fileId = idProvider.getFileid(path33, new DisabledListProgressListener());

assertEquals(fileId, path33WithId.attributes().getVersionId());
assertNotEquals(fileId, path2RWithId.attributes().getVersionId());
}
}

0 comments on commit 1cbf7e3

Please sign in to comment.