-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from DolphFlynn/proxy_config
Respect ProxyConfig when highlighting JWT's (Thanks to @serate-actual).
- Loading branch information
Showing
4 changed files
with
223 additions
and
3 deletions.
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
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,54 @@ | ||
/* | ||
Author : Dolph Flynn | ||
Copyright 2024 Dolph Flynn | ||
Licensed 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 burp.api.montoya.core; | ||
|
||
public class FakeAnnotations implements Annotations { | ||
private String notes; | ||
private HighlightColor highlightColor; | ||
|
||
@Override | ||
public String notes() { | ||
return notes; | ||
} | ||
|
||
@Override | ||
public void setNotes(String notes) { | ||
this.notes = notes; | ||
} | ||
|
||
@Override | ||
public HighlightColor highlightColor() { | ||
return highlightColor; | ||
} | ||
|
||
@Override | ||
public void setHighlightColor(HighlightColor highlightColor) { | ||
this.highlightColor = highlightColor; | ||
} | ||
|
||
@Override | ||
public Annotations withNotes(String s) { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public Annotations withHighlightColor(HighlightColor highlightColor) { | ||
throw new UnsupportedOperationException(); | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
src/test/java/burp/api/montoya/utilities/FakeByteUtils.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,63 @@ | ||
/* | ||
Author : Dolph Flynn | ||
Copyright 2024 Dolph Flynn | ||
Licensed 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 burp.api.montoya.utilities; | ||
|
||
import static java.nio.charset.StandardCharsets.UTF_8; | ||
|
||
public class FakeByteUtils implements ByteUtils{ | ||
@Override | ||
public int indexOf(byte[] bytes, byte[] bytes1) { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public int indexOf(byte[] bytes, byte[] bytes1, boolean b) { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public int indexOf(byte[] bytes, byte[] bytes1, boolean b, int i, int i1) { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public int countMatches(byte[] bytes, byte[] bytes1) { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public int countMatches(byte[] bytes, byte[] bytes1, boolean b) { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public int countMatches(byte[] bytes, byte[] bytes1, boolean b, int i, int i1) { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public String convertToString(byte[] bytes) { | ||
return new String(bytes, UTF_8); | ||
} | ||
|
||
@Override | ||
public byte[] convertFromString(String s) { | ||
throw new UnsupportedOperationException(); | ||
} | ||
} |
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,99 @@ | ||
/* | ||
Author : Dolph Flynn | ||
Copyright 2024 Dolph Flynn | ||
Licensed 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 burp.proxy; | ||
|
||
import burp.api.montoya.core.Annotations; | ||
import burp.api.montoya.core.FakeAnnotations; | ||
import burp.api.montoya.core.FakeByteArray; | ||
import burp.api.montoya.utilities.ByteUtils; | ||
import burp.api.montoya.utilities.FakeByteUtils; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
|
||
import java.util.stream.Stream; | ||
|
||
import static burp.proxy.HighlightColor.GREEN; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.params.provider.Arguments.arguments; | ||
|
||
class AnnotationsModifierTest { | ||
private final ProxyConfig config = new ProxyConfig(); | ||
private final ByteUtils byteUtils = new FakeByteUtils(); | ||
private final AnnotationsModifier annotationsModifier = new AnnotationsModifier(config, byteUtils); | ||
|
||
private static Stream<Arguments> data() { | ||
return Stream.of( | ||
arguments("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJUZXN0In0.Nabf3xakZubPnCzHT-fx0vG1iuNPeJKuSzHxUiQKf-8", "1 JWTs, 0 JWEs"), | ||
arguments("eyJlbmMiOiJBMTI4R0NNIiwiYWxnIjoiQTEyOEtXIn0.H3X6mT5HLgcFfzLoe4ku6Knhh9Ofv1eL.qF5-N_7K8VQ4yMSz.WXUNY6eg5fR4tc8Hqf5XDRM9ALGwcQyYG4IYwwg8Ctkx1UuxoV7t6UnemjzCj2sOYUqi3KYpDzrKVJpzokz0vcIem4lFe5N_ds8FAMpW0GSF9ePA8qvV99WaP0N2ECVPmgihvL6qwNhdptlLKtxcOpE41U5LnU22voPK55VF4_1j0WmTgWgZ7DwLDysp6EIDjrrt-DY.febBmP71KADmKRVfeSnv_g", "0 JWTs, 1 JWEs") | ||
); | ||
} | ||
|
||
@MethodSource("data") | ||
@ParameterizedTest | ||
void givenJWTStrings_whenHighlightJWTTrue_thenCommentAndHighlightUpdated(String data, String expectedComment) { | ||
Annotations annotations = new FakeAnnotations(); | ||
config.setHighlightColor(GREEN); | ||
config.setHighlightJWT(true); | ||
|
||
annotationsModifier.updateAnnotationsIfApplicable(annotations, data); | ||
|
||
assertThat(annotations.highlightColor()).isEqualTo(GREEN.burpColor); | ||
assertThat(annotations.notes()).isEqualTo(expectedComment); | ||
} | ||
|
||
@MethodSource("data") | ||
@ParameterizedTest | ||
void givenJWTBytes_whenHighlightJWTTrue_thenCommentAndHighlightUpdated(String data, String expectedComment) { | ||
Annotations annotations = new FakeAnnotations(); | ||
config.setHighlightColor(GREEN); | ||
config.setHighlightJWT(true); | ||
|
||
annotationsModifier.updateAnnotationsIfApplicable(annotations, new FakeByteArray(data)); | ||
|
||
assertThat(annotations.highlightColor()).isEqualTo(GREEN.burpColor); | ||
assertThat(annotations.notes()).isEqualTo(expectedComment); | ||
} | ||
|
||
@MethodSource("data") | ||
@ParameterizedTest | ||
void givenJWTStrings_whenHighlightJWTFalse_thenCommentAndHighlightNotSet(String data, String expectedComment) { | ||
Annotations annotations = new FakeAnnotations(); | ||
config.setHighlightColor(GREEN); | ||
config.setHighlightJWT(false); | ||
|
||
annotationsModifier.updateAnnotationsIfApplicable(annotations, data); | ||
|
||
assertThat(annotations.highlightColor()).isNull(); | ||
assertThat(annotations.notes()).isNull(); | ||
} | ||
|
||
@MethodSource("data") | ||
@ParameterizedTest | ||
void givenJWTBytes_whenHighlightJWTFalse_thenCommentAndHighlightNotSet(String data, String expectedComment) { | ||
Annotations annotations = new FakeAnnotations(); | ||
config.setHighlightColor(GREEN); | ||
config.setHighlightJWT(false); | ||
|
||
annotationsModifier.updateAnnotationsIfApplicable(annotations, new FakeByteArray(data)); | ||
|
||
assertThat(annotations.highlightColor()).isNull(); | ||
assertThat(annotations.notes()).isNull(); | ||
} | ||
} |