1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-07-02 11:34:53 +02:00

[Key Connector] Fix Key Connector Url test (#1308)

This commit is contained in:
Thomas Rittson 2021-11-23 21:11:47 +10:00 committed by GitHub
parent 0490314cff
commit 2973d06c9f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 54 additions and 36 deletions

View File

@ -57,20 +57,26 @@
<div class="input-group"> <div class="input-group">
<input class="form-control" formControlName="keyConnectorUrl" id="keyConnectorUrl" required> <input class="form-control" formControlName="keyConnectorUrl" id="keyConnectorUrl" required>
<div class="input-group-append"> <div class="input-group-append">
<button type="button" class="btn btn-outline-secondary" (click)="testKeyConnector()" <button type="button" class="btn btn-outline-secondary" (click)="validateKeyConnectorUrl()"
[disabled]="!enableTestKeyConnector"> [disabled]="!enableTestKeyConnector">
{{'keyConnectorTest' | i18n}} <i class="fa fa-spinner fa-spin" title="{{'loading' | i18n}}" aria-hidden="true"
*ngIf="keyConnectorUrl.pending"></i>
<span *ngIf="!keyConnectorUrl.pending">
{{'keyConnectorTest' | i18n}}
</span>
</button> </button>
</div> </div>
</div> </div>
<div class="text-danger" *ngIf="keyConnectorIsValid === false && keyConnectorUrl.pristine" role="alert"> <ng-container *ngIf="keyConnectorUrl.pristine && !keyConnectorUrl.pending">
<i class="fa fa-exclamation-circle" aria-hidden="true"></i> <div class="text-danger" *ngIf="keyConnectorUrl.hasError('invalidUrl')" role="alert">
{{'keyConnectorTestFail' | i18n}} <i class="fa fa-exclamation-circle" aria-hidden="true"></i>
</div> {{'keyConnectorTestFail' | i18n}}
<div class="text-success" *ngIf="keyConnectorIsValid && keyConnectorUrl.pristine" role="alert"> </div>
<i class="fa fa-check-circle-o" aria-hidden="true"></i> <div class="text-success" *ngIf="!keyConnectorUrl.hasError('invalidUrl')" role="alert">
{{'keyConnectorTestSuccess' | i18n}} <i class="fa fa-check-circle-o" aria-hidden="true"></i>
</div> {{'keyConnectorTestSuccess' | i18n}}
</div>
</ng-container>
</div> </div>
</ng-container> </ng-container>

View File

@ -38,8 +38,6 @@ export class SsoComponent implements OnInit {
spMetadataUrl: string; spMetadataUrl: string;
spAcsUrl: string; spAcsUrl: string;
keyConnectorIsValid: boolean;
enabled = this.fb.control(false); enabled = this.fb.control(false);
data = this.fb.group({ data = this.fb.group({
configType: [], configType: [],
@ -105,6 +103,8 @@ export class SsoComponent implements OnInit {
this.spMetadataUrl = ssoSettings.urls.spMetadataUrl; this.spMetadataUrl = ssoSettings.urls.spMetadataUrl;
this.spAcsUrl = ssoSettings.urls.spAcsUrl; this.spAcsUrl = ssoSettings.urls.spAcsUrl;
this.keyConnectorUrl.markAsDirty();
this.loading = false; this.loading = false;
} }
@ -117,12 +117,28 @@ export class SsoComponent implements OnInit {
} }
async submit() { async submit() {
if (!this.keyConnectorIsValid || this.keyConnectorUrl.dirty) this.formPromise = this.postData();
{
await this.testKeyConnector(); try {
if (!this.keyConnectorIsValid) { const response = await this.formPromise;
this.platformUtilsService.showToast('error', null, this.i18nService.t('keyConnectorTestFail'));
return; this.data.patchValue(response.data);
this.enabled.setValue(response.enabled);
this.platformUtilsService.showToast('success', null, this.i18nService.t('ssoSettingsSaved'));
} catch {
// Logged by appApiAction, do nothing
}
this.formPromise = null;
}
async postData() {
if (this.data.get('keyConnectorEnabled').value) {
await this.validateKeyConnectorUrl();
if (this.keyConnectorUrl.hasError('invalidUrl')) {
throw new Error(this.i18nService.t('keyConnectorTestFail'));
} }
} }
@ -130,30 +146,26 @@ export class SsoComponent implements OnInit {
request.enabled = this.enabled.value; request.enabled = this.enabled.value;
request.data = this.data.value; request.data = this.data.value;
this.formPromise = this.apiService.postOrganizationSso(this.organizationId, request); return this.apiService.postOrganizationSso(this.organizationId, request);
const response = await this.formPromise;
this.data.patchValue(response.data);
this.enabled.setValue(response.enabled);
this.formPromise = null;
this.platformUtilsService.showToast('success', null, this.i18nService.t('ssoSettingsSaved'));
} }
async testKeyConnector() { async validateKeyConnectorUrl() {
if (this.keyConnectorIsValid && this.keyConnectorUrl.pristine) { if (this.keyConnectorUrl.pristine) {
return; return;
} }
this.keyConnectorUrl.markAsPending();
try {
await this.apiService.getKeyConnectorAlive(this.keyConnectorUrl.value);
this.keyConnectorUrl.updateValueAndValidity();
} catch {
this.keyConnectorUrl.setErrors({
invalidUrl: true,
});
}
this.keyConnectorUrl.markAsPristine(); this.keyConnectorUrl.markAsPristine();
try {
await this.apiService.getKeyConnectorAlive(this.keyConnectorUrl.value);
} catch {
this.keyConnectorIsValid = false;
return;
}
this.keyConnectorIsValid = true;
} }
get enableTestKeyConnector() { get enableTestKeyConnector() {