@Test
 public void testCorruptChecksumAtFooter() throws Exception {
   final DirCache dc = new DirCache(pathOf("gitgit.index.badchecksum"), FS.DETECTED);
   try {
     dc.read();
     fail("Cache loaded despite corrupt checksum");
   } catch (CorruptObjectException err) {
     assertEquals("DIRC checksum mismatch", err.getMessage());
   }
 }
 @Test
 public void testUnsupportedRequiredExtension() throws Exception {
   final DirCache dc = new DirCache(pathOf("gitgit.index.aaaa"), FS.DETECTED);
   try {
     dc.read();
     fail("Cache loaded an unsupported extension");
   } catch (CorruptObjectException err) {
     assertEquals("DIRC extension 'aaaa'" + " not supported by this version.", err.getMessage());
   }
 }
示例#3
0
 @Test
 public void testInvalidType() {
   try {
     checker.check(Constants.OBJ_BAD, new byte[0]);
     fail("Did not throw CorruptObjectException");
   } catch (CorruptObjectException e) {
     final String m = e.getMessage();
     assertEquals(
         MessageFormat.format(JGitText.get().corruptObjectInvalidType2, Constants.OBJ_BAD), m);
   }
 }
示例#4
0
  @Test
  public void testInvalidTagNoObject1() {
    final StringBuilder b = new StringBuilder();

    final byte[] data = Constants.encodeASCII(b.toString());
    try {
      checker.checkTag(data);
      fail("incorrectly accepted invalid tag");
    } catch (CorruptObjectException e) {
      assertEquals("no object header", e.getMessage());
    }
  }
示例#5
0
 @Test
 public void testInvalidTreeTruncatedInObjectId() {
   final StringBuilder b = new StringBuilder();
   b.append("100644 b\0\1\2");
   final byte[] data = Constants.encodeASCII(b.toString());
   try {
     checker.checkTree(data);
     fail("incorrectly accepted an invalid tree");
   } catch (CorruptObjectException e) {
     assertEquals("truncated in object id", e.getMessage());
   }
 }
示例#6
0
 @Test
 public void testInvalidTreeNameIsDotDot() {
   final StringBuilder b = new StringBuilder();
   entry(b, "100644 ..");
   final byte[] data = Constants.encodeASCII(b.toString());
   try {
     checker.checkTree(data);
     fail("incorrectly accepted an invalid tree");
   } catch (CorruptObjectException e) {
     assertEquals("invalid name '..'", e.getMessage());
   }
 }
示例#7
0
 @Test
 public void testInvalidTreeModeNotSupportedMode2() {
   final StringBuilder b = new StringBuilder();
   entry(b, "170000 a");
   final byte[] data = Constants.encodeASCII(b.toString());
   try {
     checker.checkTree(data);
     fail("incorrectly accepted an invalid tree");
   } catch (CorruptObjectException e) {
     assertEquals("invalid mode " + 0170000, e.getMessage());
   }
 }
示例#8
0
 @Test
 public void testInvalidTreeModeStartsWithZero3() {
   final StringBuilder b = new StringBuilder();
   entry(b, "040000 a");
   final byte[] data = Constants.encodeASCII(b.toString());
   try {
     checker.checkTree(data);
     fail("incorrectly accepted an invalid tree");
   } catch (CorruptObjectException e) {
     assertEquals("mode starts with '0'", e.getMessage());
   }
 }
示例#9
0
 @Test
 public void testInvalidTreeBadSorting1() {
   final StringBuilder b = new StringBuilder();
   entry(b, "100644 foobar");
   entry(b, "100644 fooaaa");
   final byte[] data = Constants.encodeASCII(b.toString());
   try {
     checker.checkTree(data);
     fail("incorrectly accepted an invalid tree");
   } catch (CorruptObjectException e) {
     assertEquals("incorrectly sorted", e.getMessage());
   }
 }
示例#10
0
  @Test
  public void testInvalidTagNoType1() {
    final StringBuilder b = new StringBuilder();

    b.append("object ");
    b.append("be9bfa841874ccc9f2ef7c48d0c76226f89b7189");
    b.append('\n');

    final byte[] data = Constants.encodeASCII(b.toString());
    try {
      checker.checkTag(data);
      fail("incorrectly accepted invalid tag");
    } catch (CorruptObjectException e) {
      assertEquals("no type header", e.getMessage());
    }
  }
示例#11
0
  @Test
  public void testInvalidCommitInvalidTree4() {
    final StringBuilder b = new StringBuilder();

    b.append("tree  ");
    b.append("be9bfa841874ccc9f2ef7c48d0c76226f89b7189");
    b.append('\n');

    final byte[] data = Constants.encodeASCII(b.toString());
    try {
      checker.checkCommit(data);
      fail("Did not catch corrupt object");
    } catch (CorruptObjectException e) {
      assertEquals("invalid tree", e.getMessage());
    }
  }
示例#12
0
 @Test
 public void testInvalidTreeDuplicateNames4() {
   final StringBuilder b = new StringBuilder();
   entry(b, "100644 a");
   entry(b, "100644 a.c");
   entry(b, "100644 a.d");
   entry(b, "100644 a.e");
   entry(b, "40000 a");
   entry(b, "100644 zoo");
   final byte[] data = Constants.encodeASCII(b.toString());
   try {
     checker.checkTree(data);
     fail("incorrectly accepted an invalid tree");
   } catch (CorruptObjectException e) {
     assertEquals("duplicate entry names", e.getMessage());
   }
 }
示例#13
0
  public void testIncorrectBaseSize() throws IOException {
    init(4, 4);
    copy(0, 4);
    assertValidState();

    DeltaStream in =
        new DeltaStream(new ByteArrayInputStream(delta)) {
          @Override
          protected long getBaseSize() throws IOException {
            return 128;
          }

          @Override
          protected InputStream openBase() throws IOException {
            return new ByteArrayInputStream(base);
          }
        };
    try {
      in.read(new byte[4]);
      fail("did not throw an exception");
    } catch (CorruptObjectException e) {
      assertEquals(JGitText.get().baseLengthIncorrect, e.getMessage());
    }

    in =
        new DeltaStream(new ByteArrayInputStream(delta)) {
          @Override
          protected long getBaseSize() throws IOException {
            return 4;
          }

          @Override
          protected InputStream openBase() throws IOException {
            return new ByteArrayInputStream(new byte[0]);
          }
        };
    try {
      in.read(new byte[4]);
      fail("did not throw an exception");
    } catch (CorruptObjectException e) {
      assertEquals(JGitText.get().baseLengthIncorrect, e.getMessage());
    }
  }
示例#14
0
  @Test
  public void testInvalidCommitInvalidAuthor7() {
    final StringBuilder b = new StringBuilder();

    b.append("tree ");
    b.append("be9bfa841874ccc9f2ef7c48d0c76226f89b7189");
    b.append('\n');

    b.append("author a <b> 1 z");

    final byte[] data = Constants.encodeASCII(b.toString());
    try {
      checker.checkCommit(data);
      fail("Did not catch corrupt object");
    } catch (CorruptObjectException e) {
      // Yes, really, we complain about author not being
      // found as the invalid parent line wasn't consumed.
      assertEquals("invalid author", e.getMessage());
    }
  }
示例#15
0
  @Test
  public void testRejectInvalidWindowsPaths() throws Exception {
    SystemReader.setInstance(
        new MockSystemReader() {
          {
            setUnix();
          }
        });

    String path = "src/con.txt";
    DirCache dc = db.lockDirCache();
    DirCacheBuilder b = dc.builder();
    DirCacheEntry e = new DirCacheEntry(path);
    e.setFileMode(FileMode.REGULAR_FILE);
    try (ObjectInserter.Formatter formatter = new ObjectInserter.Formatter()) {
      e.setObjectId(formatter.idFor(Constants.OBJ_BLOB, Constants.encode(path)));
    }
    b.add(e);
    b.commit();
    db.readDirCache();

    SystemReader.setInstance(
        new MockSystemReader() {
          {
            setWindows();
          }
        });

    try {
      db.readDirCache();
      fail("should have rejected " + path);
    } catch (CorruptObjectException err) {
      assertEquals(MessageFormat.format(JGitText.get().invalidPath, path), err.getMessage());
      assertNotNull(err.getCause());
      assertEquals("invalid name 'CON'", err.getCause().getMessage());
    }
  }