Skip to content

Commit 9a447f1

Browse files
sergei-ivanovkrosenvold
authored andcommitted
PLXCOMP-220: added unit tests for handling invalid uid/gid in TarEntry
1 parent 1d58276 commit 9a447f1

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

src/test/java/org/codehaus/plexus/archiver/tar/PosixTarEntryTest.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public void testFileConstructor()
3030
new PosixTarEntry( new java.io.File( "/foo" ) );
3131
}
3232

33-
public void testPathSplittig()
33+
public void testPathSplitting()
3434
{
3535
PosixTarEntry pte = new PosixTarEntry( "/a/very/long/path/to/file/but/not/too/long/so/it/does/not/exceed/TarConstants.NAMELEN/plus/TarConstants.POSIX_PREFIXLEN" );
3636
assertEquals("/a/very/long/path/to", pte.prefix.toString());
@@ -44,4 +44,20 @@ public void testPathSplittig()
4444
assertEquals("", pte.prefix.toString());
4545
assertEquals("this/path/has/exactly/99/characters/one/two/three/four/five/six/seven/eight/nine/ten/eleven/twelve/", pte.name.toString());
4646
}
47+
48+
/**
49+
* Test case for PLXCOMP-220.
50+
*/
51+
public void testInvalidUidGid()
52+
{
53+
final TarEntry writtenEntry = new TarEntry( "test.java" );
54+
writtenEntry.setUserId( -1 );
55+
writtenEntry.setGroupId( -1 );
56+
final byte[] buffer = new byte[TarBuffer.DEFAULT_RCDSIZE];
57+
writtenEntry.writeEntryHeader( buffer );
58+
59+
final TarEntry readEntry = new TarEntry( buffer );
60+
assertEquals( 0, readEntry.getUserId() );
61+
assertEquals( 0, readEntry.getGroupId() );
62+
}
4763
}

src/test/java/org/codehaus/plexus/archiver/tar/TarEntryTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,28 @@
2727
public class TarEntryTest
2828
extends TestCase
2929
{
30+
3031
/**
3132
* demonstrates bug 18105 on OSes with os.name shorter than 7.
3233
*/
3334
public void testFileConstructor()
3435
{
3536
new TarEntry( new java.io.File( "/foo" ) );
3637
}
38+
39+
/**
40+
* Test case for PLXCOMP-220.
41+
*/
42+
public void testInvalidUidGid()
43+
{
44+
final TarEntry writtenEntry = new TarEntry( "test.java" );
45+
writtenEntry.setUserId( -1 );
46+
writtenEntry.setGroupId( -1 );
47+
final byte[] buffer = new byte[TarBuffer.DEFAULT_RCDSIZE];
48+
writtenEntry.writeEntryHeader( buffer );
49+
50+
final TarEntry readEntry = new TarEntry( buffer );
51+
assertEquals( 0, readEntry.getUserId() );
52+
assertEquals( 0, readEntry.getGroupId() );
53+
}
3754
}

0 commit comments

Comments
 (0)