-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CXF-5390] DeflaterEncoderDecoder needs to throw the exception if the…
… inflator can not finish the process git-svn-id: https://svn.apache.org/repos/asf/cxf/trunk@1543030 13f79535-47bb-0310-9956-ffa450edef68
- Loading branch information
Sergey Beryozkin
committed
Nov 18, 2013
1 parent
11bccec
commit 0b3894f
Showing
3 changed files
with
96 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
...security/xml/src/test/java/org/apache/cxf/rs/security/saml/DeflateEncoderDecoderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.cxf.rs.security.saml; | ||
|
||
import java.io.InputStream; | ||
import java.util.zip.DataFormatException; | ||
|
||
import org.apache.cxf.common.util.Base64Utility; | ||
import org.apache.cxf.helpers.IOUtils; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
|
||
public class DeflateEncoderDecoderTest extends Assert { | ||
|
||
@Test(expected = DataFormatException.class) | ||
public void testInvalidContent() throws Exception { | ||
DeflateEncoderDecoder inflater = new DeflateEncoderDecoder(); | ||
inflater.inflateToken("invalid_grant".getBytes()); | ||
} | ||
|
||
@Test(expected = DataFormatException.class) | ||
public void testInvalidContentAfterBase64() throws Exception { | ||
DeflateEncoderDecoder inflater = new DeflateEncoderDecoder(); | ||
byte[] base64decoded = Base64Utility.decode("invalid_grant"); | ||
inflater.inflateToken(base64decoded); | ||
} | ||
|
||
@Test | ||
public void testInflateDeflate() throws Exception { | ||
DeflateEncoderDecoder inflater = new DeflateEncoderDecoder(); | ||
byte[] deflated = inflater.deflateToken("valid_grant".getBytes()); | ||
InputStream is = inflater.inflateToken(deflated); | ||
assertNotNull(is); | ||
assertEquals("valid_grant", IOUtils.readStringFromStream(is)); | ||
} | ||
|
||
@Test | ||
public void testInflateDeflateBase64() throws Exception { | ||
DeflateEncoderDecoder inflater = new DeflateEncoderDecoder(); | ||
byte[] deflated = inflater.deflateToken("valid_grant".getBytes()); | ||
String base64String = Base64Utility.encode(deflated); | ||
byte[] base64decoded = Base64Utility.decode(base64String); | ||
InputStream is = inflater.inflateToken(base64decoded); | ||
assertNotNull(is); | ||
assertEquals("valid_grant", IOUtils.readStringFromStream(is)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters