mirror of https://github.com/jwtk/jjwt.git
#58: added toString implementations for JwtMap, DefaultJwt and DefaultJws with tests
This commit is contained in:
parent
0e8ee78fc4
commit
4d230a0725
|
@ -44,4 +44,9 @@ public class DefaultJws<B> implements Jws<B> {
|
|||
public String getSignature() {
|
||||
return this.signature;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "header=" + header + ",body=" + body + ",signature=" + signature;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,4 +37,9 @@ public class DefaultJwt<B> implements Jwt<Header,B> {
|
|||
public B getBody() {
|
||||
return body;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "header=" + header + ",body=" + body;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -150,4 +150,9 @@ public class JwtMap implements Map<String,Object> {
|
|||
public Set<Entry<String, Object>> entrySet() {
|
||||
return map.entrySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return map.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,8 @@ package io.jsonwebtoken.impl
|
|||
|
||||
import io.jsonwebtoken.JwsHeader
|
||||
import io.jsonwebtoken.Jwts
|
||||
import io.jsonwebtoken.SignatureAlgorithm
|
||||
import io.jsonwebtoken.impl.crypto.MacProvider
|
||||
import org.junit.Test
|
||||
import static org.junit.Assert.*
|
||||
|
||||
|
@ -32,4 +34,15 @@ class DefaultJwsTest {
|
|||
assertEquals jws.getBody(), 'foo'
|
||||
assertEquals jws.getSignature(), 'sig'
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToString() {
|
||||
//create random signing key for testing:
|
||||
byte[] key = MacProvider.generateKey().encoded
|
||||
String compact = Jwts.builder().claim('foo', 'bar').signWith(SignatureAlgorithm.HS256, key).compact();
|
||||
int i = compact.lastIndexOf('.')
|
||||
String signature = compact.substring(i + 1)
|
||||
def jws = Jwts.parser().setSigningKey(key).parseClaimsJws(compact)
|
||||
assertEquals 'header={alg=HS256},body={foo=bar},signature=' + signature, jws.toString()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
package io.jsonwebtoken.impl
|
||||
|
||||
import io.jsonwebtoken.Jwt
|
||||
import io.jsonwebtoken.Jwts
|
||||
import org.junit.Test
|
||||
|
||||
import static org.junit.Assert.assertEquals
|
||||
|
||||
class DefaultJwtTest {
|
||||
|
||||
@Test
|
||||
void testToString() {
|
||||
String compact = Jwts.builder().setHeaderParam('foo', 'bar').setAudience('jsmith').compact();
|
||||
Jwt jwt = Jwts.parser().parseClaimsJwt(compact);
|
||||
assertEquals 'header={foo=bar, alg=none},body={aud=jsmith}', jwt.toString()
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue