Skip to content

Commit

Permalink
Add unit tests for dynamically compute OpenID redirectUri
Browse files Browse the repository at this point in the history
Signed-off-by: Jean-Christian Simonetti <[email protected]>
  • Loading branch information
jaycci committed Apr 8, 2022
1 parent 36c4719 commit 420e102
Showing 1 changed file with 83 additions and 1 deletion.
84 changes: 83 additions & 1 deletion server/auth/types/openid/helper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* permissions and limitations under the License.
*/

import { composeLogoutUrl } from './helper';
import { composeLogoutUrl, getRootUrl } from './helper';

describe('test OIDC helper utility', () => {
test('test compose logout url', () => {
Expand Down Expand Up @@ -55,4 +55,86 @@ describe('test OIDC helper utility', () => {
composeLogoutUrl(customLogoutUrl, idpEndSessionUrl, additionalQuery)
);
});

test('test root url when trusted header unset', () => {
const config = {
openid: {
trust_dynamic_headers: false,
},
};

const core = {
http: {
getServerInfo: () => {
return {
hostname: 'server.com',
port: 80,
protocol: 'http',
};
},
},
};

const request = {
headers: {
'x-forwarded-host': 'dashboards.com:443',
'x-forwarded-proto': 'https',
},
};

expect('http://server.com:80').toEqual(getRootUrl(config, core, request));
});

test('test root url when trusted header set', () => {
const config = {
openid: {
trust_dynamic_headers: true,
},
};

const core = {
http: {
getServerInfo: () => {
return {
hostname: 'server.com',
port: 80,
protocol: 'http',
};
},
},
};

const request = {
headers: {
'x-forwarded-host': 'dashboards.com:443',
'x-forwarded-proto': 'https',
},
};

expect('https://dashboards.com:443').toEqual(getRootUrl(config, core, request));
});

test('test root url when trusted header set and no HTTP header', () => {
const config = {
openid: {
trust_dynamic_headers: true,
},
};

const core = {
http: {
getServerInfo: () => {
return {
hostname: 'server.com',
port: 80,
protocol: 'http',
};
},
},
};

const request = { headers: {} };

expect('http://server.com:80').toEqual(getRootUrl(config, core, request));
});
});

0 comments on commit 420e102

Please sign in to comment.