Skip to content

Commit 80305c2

Browse files
committed
add tests from RFC
1 parent bbfca4b commit 80305c2

File tree

9 files changed

+643
-45
lines changed

9 files changed

+643
-45
lines changed

pom.xml

Lines changed: 81 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
1+
<project xmlns="http://maven.apache.org/POM/4.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
24
<modelVersion>4.0.0</modelVersion>
35
<groupId>io.bspk</groupId>
46
<artifactId>httpsig</artifactId>
@@ -85,15 +87,50 @@
8587
<artifactId>httpcore5</artifactId>
8688
<version>5.1.4</version>
8789
</dependency>
90+
<dependency>
91+
<groupId>org.junit.platform</groupId>
92+
<artifactId>junit-platform-launcher</artifactId>
93+
<scope>test</scope>
94+
</dependency>
95+
<dependency>
96+
<groupId>org.junit.jupiter</groupId>
97+
<artifactId>junit-jupiter-engine</artifactId>
98+
<scope>test</scope>
99+
</dependency>
100+
<dependency>
101+
<groupId>org.junit.vintage</groupId>
102+
<artifactId>junit-vintage-engine</artifactId>
103+
<scope>test</scope>
104+
</dependency>
105+
<dependency>
106+
<groupId>org.slf4j</groupId>
107+
<artifactId>slf4j-simple</artifactId>
108+
<version>1.7.21</version>
109+
</dependency>
88110
</dependencies>
111+
112+
113+
<dependencyManagement>
114+
<dependencies>
115+
<dependency>
116+
<groupId>org.junit</groupId>
117+
<artifactId>junit-bom</artifactId>
118+
<version>5.12.2</version>
119+
<type>pom</type>
120+
<scope>import</scope>
121+
</dependency>
122+
</dependencies>
123+
</dependencyManagement>
124+
89125
<distributionManagement>
90126
<snapshotRepository>
91127
<id>ossrh</id>
92128
<url>https://s01.oss.sonatype.org/content/repositories/snapshots</url>
93129
</snapshotRepository>
94130
<repository>
95131
<id>ossrh</id>
96-
<url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url>
132+
<url>
133+
https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url>
97134
</repository>
98135
</distributionManagement>
99136
<build>
@@ -126,9 +163,9 @@
126163
<groupId>org.apache.maven.plugins</groupId>
127164
<artifactId>maven-javadoc-plugin</artifactId>
128165
<version>3.0.1</version>
129-
<configuration>
130-
<doclint>all,-missing</doclint>
131-
</configuration>
166+
<configuration>
167+
<doclint>all,-missing</doclint>
168+
</configuration>
132169
<executions>
133170
<execution>
134171
<id>attach-javadocs</id>
@@ -152,42 +189,44 @@
152189
</execution>
153190
</executions>
154191
</plugin>
155-
<plugin>
156-
<groupId>org.apache.maven.plugins</groupId>
157-
<artifactId>maven-resources-plugin</artifactId>
158-
<version>3.0.1</version>
159-
<executions>
160-
<execution>
161-
<id>readme</id>
162-
<phase>none</phase>
163-
<goals>
164-
<goal>copy-resources</goal>
165-
</goals>
166-
<configuration>
167-
<outputDirectory>${project.basedir}</outputDirectory>
168-
<resources>
169-
<resource>
170-
<directory>src/main/doc</directory>
171-
<includes>
172-
<include>README.md</include>
173-
</includes>
174-
<filtering>true</filtering>
175-
</resource>
176-
</resources>
177-
<encoding>UTF-8</encoding>
178-
</configuration>
179-
</execution>
180-
</executions>
181-
</plugin>
182-
<plugin>
183-
<groupId>org.apache.maven.plugins</groupId>
184-
<artifactId>maven-release-plugin</artifactId>
185-
<version>3.0.0-M4</version>
186-
<configuration>
187-
<preparationGoals>resources:copy-resources@readme scm:add -Dincludes=README.md</preparationGoals>
188-
<completionGoals>resources:copy-resources@readme scm:add -Dincludes=README.md</completionGoals>
189-
</configuration>
190-
</plugin>
191-
</plugins>
192+
<plugin>
193+
<groupId>org.apache.maven.plugins</groupId>
194+
<artifactId>maven-resources-plugin</artifactId>
195+
<version>3.0.1</version>
196+
<executions>
197+
<execution>
198+
<id>readme</id>
199+
<phase>none</phase>
200+
<goals>
201+
<goal>copy-resources</goal>
202+
</goals>
203+
<configuration>
204+
<outputDirectory>${project.basedir}</outputDirectory>
205+
<resources>
206+
<resource>
207+
<directory>src/main/doc</directory>
208+
<includes>
209+
<include>README.md</include>
210+
</includes>
211+
<filtering>true</filtering>
212+
</resource>
213+
</resources>
214+
<encoding>UTF-8</encoding>
215+
</configuration>
216+
</execution>
217+
</executions>
218+
</plugin>
219+
<plugin>
220+
<groupId>org.apache.maven.plugins</groupId>
221+
<artifactId>maven-release-plugin</artifactId>
222+
<version>3.0.0-M4</version>
223+
<configuration>
224+
<preparationGoals>resources:copy-resources@readme scm:add
225+
-Dincludes=README.md</preparationGoals>
226+
<completionGoals>resources:copy-resources@readme scm:add
227+
-Dincludes=README.md</completionGoals>
228+
</configuration>
229+
</plugin>
230+
</plugins>
192231
</build>
193232
</project>

src/main/java/io/bspk/httpsig/ComponentProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ default String getComponentValue(StringItem componentIdentifier) {
7272
return getQuery();
7373
case "@status":
7474
return getStatus();
75-
case "@query-params":
75+
case "@query-param":
7676
{
7777
if (componentIdentifier.getParams().containsKey("name")) {
7878
Item<? extends Object> nameParameter = componentIdentifier.getParams().get("name");

src/main/java/io/bspk/httpsig/SignatureBaseBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public byte[] createSignatureBase() {
4949
sigParams.toComponentValue().serializeTo(base);
5050

5151

52-
log.info("~~~ Signature Base :\n ~~~ : {}", Joiner.on("\n~~~ : ").join(Splitter.on("\n").split(base.toString())));
52+
//log.info("~~~ Signature Base :\n ~~~ : {}", Joiner.on("\n~~~ : ").join(Splitter.on("\n").split(base.toString())));
5353

5454
return base.toString().getBytes();
5555
}

src/main/java/io/bspk/httpsig/UriRequestComponentProviderAdapter.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.util.List;
66

77
import org.apache.hc.core5.http.NameValuePair;
8+
import org.apache.hc.core5.net.PercentCodec;
89
import org.apache.hc.core5.net.WWWFormCodec;
910

1011
/**
@@ -68,7 +69,7 @@ public String getPath()
6869
@Override
6970
public String getQuery()
7071
{
71-
return uri.getQuery();
72+
return "?" + uri.getQuery();
7273
}
7374

7475

@@ -79,6 +80,7 @@ public String getQueryParams(String name)
7980
return params.stream()
8081
.filter(p -> p.getName().equals(name))
8182
.map(NameValuePair::getValue)
83+
.map(v -> PercentCodec.encode(v, Charset.defaultCharset()))
8284
.reduce((a, b) -> {
8385
throw new IllegalArgumentException("Found two named parameters, unsupported opperation");
8486
})
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package io.bspk.httpsig;
2+
3+
import java.util.stream.Collectors;
4+
5+
import com.google.common.base.CharMatcher;
6+
import com.google.common.base.Splitter;
7+
8+
public class Crunchwrap {
9+
10+
/**
11+
* Unwrap a string per RFC 8792
12+
*/
13+
public static String unwrap(String wrapped) {
14+
15+
boolean[] isWrapping = {false}; // this uses an array to get around java's immutable inner variable limitation
16+
String unwrapped = Splitter.on("\n").splitToList(wrapped).stream()
17+
.map(line -> {
18+
if (isWrapping[0]) {
19+
line = CharMatcher.whitespace().trimLeadingFrom(line); // if we're wrapping, trim the leading whitespace from the value
20+
}
21+
22+
if (line.endsWith("\\")) {
23+
isWrapping[0] = true; // if we end with a newline, the next line is wrapped
24+
line = CharMatcher.is('\\').trimTrailingFrom(line); // trim the trailing backslash
25+
} else {
26+
isWrapping[0] = false;
27+
line = line + '\n'; // we add back a newline since it's not wrapping to the next line
28+
}
29+
return line;
30+
}).collect(Collectors.joining()); // note this removes all the internal newlines, too
31+
32+
// awkwardly trim off the trailing newline
33+
if (unwrapped.endsWith("\n")) {
34+
unwrapped = unwrapped.substring(0, unwrapped.length() - 1);
35+
}
36+
37+
return unwrapped;
38+
}
39+
40+
}

0 commit comments

Comments
 (0)