Determining auth type in a pre-request script

I’m writing tests for a service that uses either Bearer or Basic authorization but requires slightly different request URLs for the two authorization types. I want to be able to specify authorization at the collection level (except as noted in the next paragraph) and have the requests adjust themselves to match the requirements of the selected authorization type.

The collection includes a folder of requests that override the collection-level authorization in order to make sure both types of authorization are working, regardless of which type is selected for the other tests in the collection.

I’ve attempted to write a collection-level pre-request script that checks the request’s authorization type in order to adjust the URL as necessary, but the Authorization header is not set when the script runs, and I haven’t been able to find any other way to check the request’s authorization type.

For example, the following pre-request script always sets an auth-header variable to ‘(none)’ if no Authorization header is manually defined, even if authorization is configured. The auth-type value is set to ‘(no auth)’.

pm.environment.set('auth-header', pm.request.getHeaders()['Authorization'] || '(none)');
if (pm.request.auth) {
  pm.environment.set('auth-type', pm.request.auth.type || '(auth, no type)');
else {
  pm.environment.set('auth-type', '(no auth)');

Am I missing something, or is this just not possible? I suppose I could set the authorization in pre-request scripts based on the value of an environment variable, but I think that would be harder to understand and maintain.

@JessePelton This is because the auth property on the request is meant to represent the authentication helper associated with that request itself. Hence, details on the actual auth helper being used (inherited) from one of the parents would not be present here. This would be a useful addition to the contextual information provided within the sandboxed testing environment, thanks for pointing it out.

@kunagpal, should I file an enhancement request?

Yes, could you create one here: