Skip to content

Commit f6fda73

Browse files
committed
Override duplicate "Authorization" header with Header from Parent, to align with Postman app behavior
Signed-off-by: Gopal S Akshintala <[email protected]>
1 parent a05f5db commit f6fda73

File tree

8 files changed

+29
-28
lines changed

8 files changed

+29
-28
lines changed

README.adoc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ endif::[]
1818
:pmtemplates: src/integrationTest/resources/pm-templates
1919
:imagesdir: docs/images
2020
:prewrap!:
21-
:revoman-version: 0.7.9
21+
:revoman-version: 0.8.0
2222

2323
'''
2424

2525
*ReṼoman* is an API automation tool for JVM (Java/Kotlin) from the API-first SaaS company, *Salesforce*. It re-imagines API automation by letting you execute a Postman collection in a JVM program/test.
2626

27-
NOTE: NO licensed Postman SDKs are used inside this project. This is written ground up natively in JVM
27+
NOTE: NO licensed Postman SDKs are used inside this project. This is written ground up natively in JVM
2828

2929
'''
3030

@@ -55,7 +55,7 @@ to always be ready for Manually trying them out importing into Postman.
5555

5656
* ReṼoman may be similar to Newman or Postman CLI when it comes to executing a Postman collection, but the _similarities end there_
5757
* Newman or Postman CLI are built for node and cannot be executed within a JVM. Even if you are able to run with some hacky way, there is no easy way to assert results.
58-
* Built for the JVM, ReṼoman fits naturally within your current JVM stack.
58+
* Built for the JVM, ReṼoman fits naturally within your current JVM stack.
5959
* Its <<#_type_safety_with_flexible_json_pojo_marshallingserialization_and_unmarshallingdeserialization,Type Safety>> bridges the gap between strongly-typed JVM code and flexible JSON.
6060
* It has more features, like <<#_pre_step_and_post_step_hooks,Hooks>> feature that lets you plug in your custom JVM code in-between the execution. The <<Rundown>> is much richer in providing execution information than the link:{pmtemplates}/restfulapidev/postman-cli-reports/restful-api.dev-2025-04-14-13-16-43.json[newman/postman-cli reports]
6161
* It's not limited to Postman templates. We have plans to support more popular templates formats like ThunderClient, Bruno, etc. which offers versatality for consumers.
@@ -661,7 +661,7 @@ IMPORTANT: It is not supported to load `node_modules` from jar. For example, `/U
661661
662662
image::node_modules.png[]
663663
664-
* If `node_modules` is ignored on your git repo, you can force-add to check in using the command `git add -all -f <path>/node_modules`
664+
* If `node_modules` is ignored on your git repo, you can force-add to check in using the command `git add --all -f <path>/node_modules`
665665
====
666666

667667
CAUTION: The recommendation is not to add too much code in <<Pre-req and Post-res scripts>>, as it's not intuitive to troubleshoot through debugging. Use it for simple operations that can be understood without debugging, and use <<#_pre_step_and_post_step_hooks,Pre-Step /Post-Step Hooks>> for any non-trivial operations, which are intuitive to debug.

buildSrc/src/main/kotlin/Config.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
* ************************************************************************************************
77
*/
88
const val GROUP_ID = "com.salesforce.revoman"
9-
const val VERSION = "0.7.9"
9+
const val VERSION = "0.8.0"
1010
const val ARTIFACT_ID = "revoman"
1111
const val STAGING_PROFILE_ID = "1ea0a23e61ba7d"

renovate.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"matchPackageNames": [
1919
"org.graalvm.sdk:graal-sdk",
2020
"org.graalvm.js:js",
21+
"org.http4k:http4k-bom",
2122
"org.http4k:http4k-core",
2223
"org.http4k:http4k-client-apache",
2324
"org.http4k:http4k-format-moshi"

src/integrationTest/resources/pm-templates/core/milestone/bmp-create-runtime.postman_collection.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
22
"info": {
3-
"_postman_id": "6d4408f2-0e8e-43dc-9e0e-958825246388",
3+
"_postman_id": "b6a7d9e6-6176-45a6-ad41-ea63a0969cd4",
44
"name": "bmp-create-runtime",
55
"description": "- SalesOpsRep: Create an Order using PST and Activate it",
66
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
77
"_exporter_id": "23827434",
8-
"_collection_link": "https://salesforce-734821.postman.co/workspace/1c6fbe60-fabb-4988-890b-b032cf03e25d/collection/23827434-6d4408f2-0e8e-43dc-9e0e-958825246388?source=collection_link"
8+
"_collection_link": "https://salesforce-734821.postman.co/workspace/Ape~84673b5d-fa1c-4ac7-ab44-1073ee53332d/collection/23827434-b6a7d9e6-6176-45a6-ad41-ea63a0969cd4?action=share&source=collection_link&creator=23827434"
99
},
1010
"item": [
1111
{
@@ -185,7 +185,13 @@
185185
],
186186
"request": {
187187
"method": "POST",
188-
"header": [],
188+
"header": [
189+
{
190+
"key": "Authorization",
191+
"value": "Bearer 00DLT000005y8W6!AQEAQM_BzmGAc9C50ew5dHciarq4jL2hDuUcvpDDQnqw3SIs5Snt8ZCQJX2lbe9swZW6vHPy9.paaSYRkjHzhMd.Fx3EZ6Gc",
192+
"type": "text"
193+
}
194+
],
189195
"body": {
190196
"mode": "raw",
191197
"raw": "{\n \"pricingPref\": \"{{$pricingPref}}\",\n \"configurationPref\": {\n \"configurationMethod\": \"skip\"\n },\n \"graph\": {\n \"graphId\": \"{{$requestName}}\",\n \"records\": [\n {\n \"referenceId\": \"refOrder\",\n \"record\": {\n \"attributes\": {\n \"type\": \"Order\",\n \"method\": \"POST\"\n },\n \"Status\": \"Draft\",\n \"AccountId\": \"{{accountId}}\",\n \"Pricebook2Id\": \"{{standardPricebookId}}\",\n \"BillToContactId\": \"{{contactId}}\",\n \"EffectiveDate\": \"2024-11-20\",\n \"BillingStreet\": \"Block 3, DivyaSree Orion IT/ITES SEZ, Raidurg Village\",\n \"BillingCity\": \"Hyderabad\",\n \"BillingState\": \"TS\",\n \"BillingPostalCode\": \"500032\",\n \"BillingCountry\": \"India\",\n \"ShippingStreet\": \"Block 3, DivyaSree Orion IT/ITES SEZ, Raidurg Village\",\n \"ShippingCity\": \"Hyderabad\",\n \"ShippingState\": \"TS\",\n \"ShippingPostalCode\": \"500032\",\n \"ShippingCountry\": \"India\"\n }\n },\n {\n \"referenceId\": \"refAppTag\",\n \"record\": {\n \"attributes\": {\n \"type\": \"AppUsageAssignment\",\n \"method\": \"POST\"\n },\n \"AppUsageType\": \"RevenueLifecycleManagement\",\n \"RecordId\": \"@{refOrder.id}\"\n }\n },\n {\n \"referenceId\": \"refOrderAction\",\n \"record\": {\n \"attributes\": {\n \"type\": \"OrderAction\",\n \"method\": \"POST\"\n },\n \"OrderId\": \"@{refOrder.id}\",\n \"Type\": \"Add\"\n }\n },\n {\n \"referenceId\": \"OrderItem1\",\n \"record\": {\n \"attributes\": {\n \"type\": \"OrderItem\",\n \"method\": \"POST\"\n },\n \"OrderId\": \"@{refOrder.id}\",\n \"PricebookEntryId\": \"{{oneTimePriceBookEntryId}}\",\n \"Product2Id\": \"{{oneTimeProductId}}\",\n \"Quantity\": {{$quantity}},\n \"UnitPrice\": {{$unitPrice}},\n \"OrderActionId\": \"@{refOrderAction.id}\"\n }\n }\n ]\n }\n}",

src/integrationTest/resources/pm-templates/core/milestone/env.postman_environment.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@
44
"values": [
55
{
66
"key" : "baseUrl",
7-
"value" : "https://orgfarm-fe6a79aee6.test1.my.pc-rnd.salesforce.com/",
7+
"value" : "https://dlt000005y8w62ai.test1.my.pc-rnd.salesforce.com",
88
"type" : "default",
99
"enabled" : true
1010
},
1111
{
1212
"key" : "username",
13-
"value" : "[email protected]",
13+
"value" : "[email protected]",
1414
"type" : "default",
1515
"enabled" : true
1616
},
1717
{
1818
"key" : "password",
19-
"value" : "orgfarm1234",
19+
"value" : "test1234",
2020
"type" : "default",
2121
"enabled" : true
2222
},

src/main/kotlin/com/salesforce/revoman/ReVoman.kt

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -189,13 +189,7 @@ object ReVoman {
189189
// PRE-REQ-JS
190190
val item = regexReplacer.replaceVariablesInPmItem(itemWithRegex, pm)
191191
val httpRequest = item.request.toHttpRequest(moshiReVoman)
192-
fireHttpRequest(
193-
step,
194-
item.request.auth,
195-
httpRequest,
196-
kick.insecureHttp(),
197-
moshiReVoman,
198-
)
192+
fireHttpRequest(step, httpRequest, kick.insecureHttp(), moshiReVoman)
199193
.mapLeft { sr.copy(requestInfo = Left(it).toVavr()) }
200194
.map {
201195
sr.copy(

src/main/kotlin/com/salesforce/revoman/internal/exe/HttpRequest.kt

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ package com.salesforce.revoman.internal.exe
99

1010
import arrow.core.Either
1111
import com.salesforce.revoman.internal.json.MoshiReVoman
12-
import com.salesforce.revoman.internal.postman.template.Auth
1312
import com.salesforce.revoman.output.ExeType.HTTP_REQUEST
1413
import com.salesforce.revoman.output.report.Step
1514
import com.salesforce.revoman.output.report.TxnInfo
@@ -23,19 +22,15 @@ import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory
2322
import org.apache.hc.core5.http.config.RegistryBuilder
2423
import org.apache.hc.core5.ssl.SSLContextBuilder
2524
import org.http4k.client.ApacheClient
26-
import org.http4k.core.Filter
2725
import org.http4k.core.HttpHandler
28-
import org.http4k.core.NoOp
2926
import org.http4k.core.Request
3027
import org.http4k.core.Response
3128
import org.http4k.core.then
32-
import org.http4k.filter.ClientFilters
3329
import org.http4k.filter.DebuggingFilters
3430

3531
@JvmSynthetic
3632
internal fun fireHttpRequest(
3733
currentStep: Step,
38-
auth: Auth?,
3934
httpRequest: Request,
4035
insecureHttp: Boolean,
4136
moshiReVoman: MoshiReVoman,
@@ -44,14 +39,13 @@ internal fun fireHttpRequest(
4439
// * NOTE gopala.akshintala 06/08/22: Preparing httpClient for each step,
4540
// * as there can be intermediate auths
4641
// ! TODO 29/01/24 gopala.akshintala: When would bearer token size be > 1?
47-
prepareHttpClient(auth?.bearer?.firstOrNull()?.value, insecureHttp)(httpRequest)
42+
prepareHttpClient(insecureHttp)(httpRequest)
4843
}
4944
.mapLeft { HttpRequestFailure(it, TxnInfo(httpMsg = httpRequest, moshiReVoman = moshiReVoman)) }
5045
.map { TxnInfo(httpMsg = it, moshiReVoman = moshiReVoman) }
5146

52-
private fun prepareHttpClient(bearerToken: String?, insecureHttp: Boolean): HttpHandler =
47+
private fun prepareHttpClient(insecureHttp: Boolean): HttpHandler =
5348
DebuggingFilters.PrintRequestAndResponse()
54-
.then(if (bearerToken.isNullOrEmpty()) Filter.NoOp else ClientFilters.BearerAuth(bearerToken))
5549
.then(if (insecureHttp) ApacheClient(client = insecureApacheHttpClient()) else ApacheClient())
5650

5751
/** Only for Testing. DO NOT USE IN PROD */

src/main/kotlin/com/salesforce/revoman/internal/postman/template/Template.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import org.http4k.core.Uri
1818
import org.http4k.core.queryParametersEncoded
1919
import org.http4k.core.with
2020
import org.http4k.lens.Header.CONTENT_TYPE
21+
import org.http4k.lens.bearerAuth
2122

2223
@JsonClass(generateAdapter = true)
2324
internal data class Template(val item: List<Item>, val auth: Auth?)
@@ -86,8 +87,13 @@ data class Request(
8687
.Request(Method.valueOf(method), uri)
8788
.headers(header.map { it.key.trim() to it.value.trim() })
8889
.body(cleansedRawBody)
89-
return if (contentTypeHeader != null) request.with(CONTENT_TYPE of contentTypeHeader)
90-
else request
90+
val requestWithAuth =
91+
auth?.bearer?.firstOrNull()?.value?.let {
92+
// * NOTE 11 May 2025 gopala.akshintala: Auth in headers will be overridden by Auth from
93+
// request, to align with Postman app behavior
94+
request.removeHeader("Authorization").bearerAuth(it)
95+
} ?: request
96+
return contentTypeHeader?.let { requestWithAuth.with(CONTENT_TYPE of it) } ?: requestWithAuth
9197
}
9298

9399
companion object {

0 commit comments

Comments
 (0)