@@ -89,6 +89,25 @@ void getSignedURLWithCannedPolicy_producesValidUrl() {
89
89
assertThat (expected ).isEqualTo (url );
90
90
}
91
91
92
+ @ Test
93
+ void getSignedURLWithCannedPolicy_withQueryParams_producesValidUrl () {
94
+ Instant expirationDate = LocalDate .of (2024 , 1 , 1 ).atStartOfDay ().toInstant (ZoneOffset .of ("Z" ));
95
+ String resourceUrlWithQueryParams = "https://d1npcfkc2mojrf.cloudfront.net/s3ObjectKey?a=b&c=d" ;
96
+ SignedUrl signedUrl =
97
+ cloudFrontUtilities .getSignedUrlWithCannedPolicy (r -> r
98
+ .resourceUrl (resourceUrlWithQueryParams )
99
+ .privateKey (keyPair .getPrivate ())
100
+ .keyPairId ("keyPairId" )
101
+ .expirationDate (expirationDate ));
102
+ String url = signedUrl .url ();
103
+
104
+ String signature = url .substring (url .indexOf ("&Signature" ), url .indexOf ("&Key-Pair-Id" ));
105
+ String expected = "https://d1npcfkc2mojrf.cloudfront.net/s3ObjectKey?a=b&c=d&Expires=1704067200"
106
+ + signature
107
+ + "&Key-Pair-Id=keyPairId" ;
108
+ assertThat (expected ).isEqualTo (url );
109
+ }
110
+
92
111
@ Test
93
112
void getSignedURLWithCustomPolicy_producesValidUrl () throws Exception {
94
113
Instant activeDate = LocalDate .of (2022 , 1 , 1 ).atStartOfDay ().toInstant (ZoneOffset .of ("Z" ));
@@ -116,6 +135,30 @@ void getSignedURLWithCustomPolicy_producesValidUrl() throws Exception {
116
135
assertThat (expected ).isEqualTo (url );
117
136
}
118
137
138
+ @ Test
139
+ void getSignedURLWithCustomPolicy_withQueryParams_producesValidUrl () {
140
+ Instant activeDate = LocalDate .of (2022 , 1 , 1 ).atStartOfDay ().toInstant (ZoneOffset .of ("Z" ));
141
+ Instant expirationDate = LocalDate .of (2024 , 1 , 1 ).atStartOfDay ().toInstant (ZoneOffset .of ("Z" ));
142
+ String ipRange = "1.2.3.4" ;
143
+ String resourceUrlWithQueryParams = "https://d1npcfkc2mojrf.cloudfront.net/s3ObjectKey?a=b&c=d" ;
144
+ SignedUrl signedUrl =
145
+ cloudFrontUtilities .getSignedUrlWithCustomPolicy (r -> r
146
+ .resourceUrl (resourceUrlWithQueryParams )
147
+ .privateKey (keyPair .getPrivate ())
148
+ .keyPairId ("keyPairId" )
149
+ .expirationDate (expirationDate )
150
+ .activeDate (activeDate )
151
+ .ipRange (ipRange ));
152
+ String url = signedUrl .url ();
153
+ String policy = url .substring (url .indexOf ("Policy=" ) + 7 , url .indexOf ("&Signature" ));
154
+ String signature = url .substring (url .indexOf ("&Signature" ), url .indexOf ("&Key-Pair-Id" ));
155
+ String expected = "https://d1npcfkc2mojrf.cloudfront.net/s3ObjectKey?a=b&c=d&Policy="
156
+ + policy
157
+ + signature
158
+ + "&Key-Pair-Id=keyPairId" ;
159
+ assertThat (expected ).isEqualTo (url );
160
+ }
161
+
119
162
@ Test
120
163
void getSignedURLWithCustomPolicy_withIpRangeOmitted_producesValidUrl () throws Exception {
121
164
Instant activeDate = LocalDate .of (2022 , 1 , 1 ).atStartOfDay ().toInstant (ZoneOffset .of ("Z" ));
0 commit comments