Skip to content

Commit

Permalink
Switched from jacoco to open-clover. Updated GzipCompressionCodec to …
Browse files Browse the repository at this point in the history
…improve coverage report.
  • Loading branch information
dogeared committed Sep 10, 2017
1 parent 8797f1d commit 5ffee1e
Show file tree
Hide file tree
Showing 6 changed files with 154 additions and 13 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
.mtj.tmp/

# Package Files #
*.jar
*.war
*.ear

Expand Down
35 changes: 35 additions & 0 deletions .travis.settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">

<profiles>
<profile>
<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>bintray-jwtk-coveralls-maven-plugin</id>
<name>bintray</name>
<url>https://dl.bintray.com/jwtk/coveralls-maven-plugin</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>bintray-jwtk-coveralls-maven-plugin</id>
<name>bintray-plugins</name>
<url>https://dl.bintray.com/jwtk/coveralls-maven-plugin</url>
</pluginRepository>
</pluginRepositories>
<id>bintray</id>
</profile>
</profiles>
<activeProfiles>
<activeProfile>bintray</activeProfile>
<!-- any others: -->
</activeProfiles>
</settings>
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ install: echo "No need to run mvn install -DskipTests then mvn install. Running
script: mvn install

after_success:
- test -z "$BUILD_COVERAGE" || mvn clean test jacoco:report coveralls:report
- test -z "$BUILD_COVERAGE" || mvn clean test clover:check clover:clover coveralls:report

52 changes: 43 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,29 @@
<url>https://travis-ci.org/jwtk/jjwt</url>
</ciManagement>

<!-- temporary fix until official release of coverall-maven-plugin with clover support -->
<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>bintray-jwtk-coveralls-maven-plugin</id>
<name>bintray</name>
<url>https://dl.bintray.com/jwtk/coveralls-maven-plugin</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>bintray-jwtk-coveralls-maven-plugin</id>
<name>bintray-plugins</name>
<url>https://dl.bintray.com/jwtk/coveralls-maven-plugin</url>
</pluginRepository>
</pluginRepositories>
<!-- temporary fix until official release of coverall-maven-plugin with clover support -->

<properties>

<maven.jar.version>3.0.2</maven.jar.version>
Expand All @@ -73,6 +96,7 @@
<junit.version>4.12</junit.version>
<powermock.version>1.6.6</powermock.version>
<failsafe.plugin.version>2.19.1</failsafe.plugin.version>
<clover.version>4.2.0</clover.version>

</properties>

Expand Down Expand Up @@ -151,7 +175,6 @@
<version>4.12</version>
<scope>test</scope>
</dependency>

</dependencies>

<build>
Expand Down Expand Up @@ -270,19 +293,28 @@
</executions>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.9</version>
<groupId>org.openclover</groupId>
<artifactId>clover-maven-plugin</artifactId>
<version>${clover.version}</version>
<configuration>
<excludes>
<exclude>**/io/jsonwebtoken/lang/*</exclude>
<exclude>**/*Test*</exclude>
<!-- leaving out lang as it mostly comes from other sources -->
<exclude>io/jsonwebtoken/lang/*</exclude>
</excludes>
<methodPercentage>100%</methodPercentage>
<statementPercentage>100%</statementPercentage>
<conditionalPercentage>100%</conditionalPercentage>
<targetPercentage>100%</targetPercentage>
</configuration>
<executions>
<execution>
<id>prepare-agent</id>
<id>clover</id>
<phase>test</phase>
<goals>
<goal>prepare-agent</goal>
<goal>instrument</goal>
<goal>check</goal>
<goal>clover</goal>
</goals>
</execution>
</executions>
Expand Down Expand Up @@ -331,11 +363,13 @@
</instructions>
</configuration>
</plugin>
<!-- Temporarily host coveralls SNAPSHOT with clover support locally -->
<plugin>
<groupId>org.eluder.coveralls</groupId>
<groupId>org.jwtk.coveralls</groupId>
<artifactId>coveralls-maven-plugin</artifactId>
<version>4.3.0</version>
<version>4.4.0</version>
</plugin>
<!-- Temporarily host coveralls SNAPSHOT with clover support locally -->
</plugins>
</build>
<profiles>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@ protected byte[] doDecompress(byte[] compressed) throws IOException {
inputStream = new ByteArrayInputStream(compressed);
gzipInputStream = new GZIPInputStream(inputStream);
outputStream = new ByteArrayOutputStream();
int read;
while ((read = gzipInputStream.read(buffer)) != -1) {
int read = gzipInputStream.read(buffer);
while (read != -1) {
outputStream.write(buffer, 0, read);
read = gzipInputStream.read(buffer);
}
return outputStream.toByteArray();
} finally {
Expand Down
72 changes: 72 additions & 0 deletions src/test/groovy/io/jsonwebtoken/JwtParserTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -1518,4 +1518,76 @@ class JwtParserTest {
assertTrue e.getMessage().startsWith('JWT expired at ')
}
}

@Test
void testParseMalformedJwt() {

String header = '{"alg":"none"}'

String payload = '{"subject":"Joe"}'

String badSig = ";aklsjdf;kajsd;fkjas;dklfj"

String bogus = 'bogus'

String bad = TextCodec.BASE64.encode(header) + '.' +
TextCodec.BASE64.encode(payload) + '.' +
TextCodec.BASE64.encode(badSig) + '.' +
TextCodec.BASE64.encode(bogus)


try {
Jwts.parser().setSigningKey(randomKey()).parse(bad)
fail()
} catch (MalformedJwtException se) {
assertEquals 'JWT strings must contain exactly 2 period characters. Found: 3', se.message
}

}

@Test
void testNoHeaderNoSig() {
String payload = '{"subject":"Joe"}'

String jwtStr = '.' + TextCodec.BASE64.encode(payload) + '.'

Jwt jwt = Jwts.parser().parse(jwtStr)

assertTrue jwt.header == null
assertEquals 'Joe', jwt.body.get('subject')
}

@Test
void testNoHeaderSig() {
String payload = '{"subject":"Joe"}'

String sig = ";aklsjdf;kajsd;fkjas;dklfj"

String jwtStr = '.' + TextCodec.BASE64.encode(payload) + '.' + TextCodec.BASE64.encode(sig)

try {
Jwt jwt = Jwts.parser().parse(jwtStr)
fail()
} catch (MalformedJwtException se) {
assertEquals 'JWT string has a digest/signature, but the header does not reference a valid signature algorithm.', se.message
}
}

@Test
void testBadHeaderSig() {
String header = '{"alg":"none"}'

String payload = '{"subject":"Joe"}'

String sig = ";aklsjdf;kajsd;fkjas;dklfj"

String jwtStr = TextCodec.BASE64.encode(payload) + '.' + TextCodec.BASE64.encode(payload) + '.' + TextCodec.BASE64.encode(sig)

try {
Jwt jwt = Jwts.parser().parse(jwtStr)
fail()
} catch (MalformedJwtException se) {
assertEquals 'JWT string has a digest/signature, but the header does not reference a valid signature algorithm.', se.message
}
}
}

0 comments on commit 5ffee1e

Please sign in to comment.