Skip to content
This repository has been archived by the owner on Apr 19, 2023. It is now read-only.

Commit

Permalink
added test smtp settings endpoint support (#181)
Browse files Browse the repository at this point in the history
  • Loading branch information
edewit authored Jun 21, 2021
1 parent dfd278c commit 08872c1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/resources/realms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import TestLdapConnectionRepresentation from '../defs/testLdapConnection';

import {KeycloakAdminClient} from '../client';
import {RealmEventsConfigRepresentation} from '../defs/realmEventsConfigRepresentation';
import ComponentRepresentation from '../defs/componentRepresentation';

export class Realms extends Resource {
/**
Expand Down Expand Up @@ -253,6 +254,12 @@ export class Realms extends Resource {
urlParamKeys: ['realm'],
});

public testSMTPConnection = this.makeUpdateRequest<{realm: string}, Record<string, string | number>>({
method: 'POST',
path: '/{realm}/testSMTPConnection',
urlParamKeys: ['realm'],
});

public getRealmSpecificLocales = this.makeRequest<{realm: string}, string[]>({
method: 'GET',
path: '/{realm}/localization',
Expand Down
20 changes: 19 additions & 1 deletion test/realms.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as chai from 'chai';
import {KeycloakAdminClient} from '../src/client';
import {credentials} from './constants';
import faker from 'faker';
import {fail} from 'assert';
const expect = chai.expect;


Expand Down Expand Up @@ -257,7 +258,7 @@ describe('Realms', () => {
});
});

describe('Realm test ldap settings', () => {
describe('Realm connection settings', () => {
it('should fail with invalid ldap settings', async () => {
try {
await kcAdminClient.realms.testLDAPConnection({realm: 'master'}, {
Expand All @@ -270,6 +271,23 @@ describe('Realms', () => {
startTls: '',
useTruststoreSpi: 'ldapsOnly',
});
fail('exception should have been thrown');
} catch (error) {
expect(error).to.be.ok;
}
});

it('should fail with invalid smtp settings', async () => {
try {
const user = (await kcAdminClient.users.find({username: credentials.username}))[0];
user.email = '[email protected]';
await kcAdminClient.users.update({id: user.id!}, user);
await kcAdminClient.realms.testSMTPConnection({realm: 'master'}, {
from: '[email protected]',
host: 'localhost',
port: 3025,
});
fail('exception should have been thrown');
} catch (error) {
expect(error).to.be.ok;
}
Expand Down

0 comments on commit 08872c1

Please sign in to comment.