Skip to content

Commit

Permalink
feat: Ui system test for Management Service TLS certificate (#1886)
Browse files Browse the repository at this point in the history
* feat: ui system test for management service TLS certificate

Refs: XRDDEV-1203

* fix: test fixes

Refs: XRDDEV-1203

* fix: test fixes

Refs: XRDDEV-1203

* fix: refacto fixes

Refs: XRDDEV-1203

* fix: little tests fixes

Refs: XRDDEV-1203
  • Loading branch information
enelir committed Dec 8, 2023
1 parent fbf849a commit 917d44c
Show file tree
Hide file tree
Showing 12 changed files with 385 additions and 60 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
/*
* The MIT License
* Copyright (c) 2019- Nordic Institute for Interoperability Solutions (NIIS)
* Copyright (c) 2018 Estonian Information System Authority (RIA),
* Nordic Institute for Interoperability Solutions (NIIS), Population Register Centre (VRK)
* Copyright (c) 2015-2017 Estonian Information System Authority (RIA), Population Register Centre (VRK)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.niis.xroad.cs.test.ui.glue;

import io.cucumber.java.en.Step;
import org.niis.xroad.cs.test.ui.page.SettingsTlsCertificatesPageObj;

import java.io.File;

import static com.codeborne.selenide.Condition.disabled;
import static com.codeborne.selenide.Condition.enabled;
import static com.codeborne.selenide.Condition.visible;
import static org.assertj.core.api.Assertions.assertThat;
import static org.niis.xroad.common.test.ui.utils.VuetifyHelper.vTextField;

public class SettingsTlsCertificatesStepDefs extends BaseUiStepDefs {

private static final String DOWNLOADED_CERTIFICATE = "DOWNLOADED_CERTIFICATE";
private static final String DOWNLOADED_CSR = "DOWNLOADED_CSR";
private final SettingsTlsCertificatesPageObj settingsTlsCertificatesPageObj = new SettingsTlsCertificatesPageObj();

@Step("TLS Certificates sub-tab is selected")
public void navigateTlsCertificatesSubTab() {
commonPageObj.subMenu.tlsCertificatesTab().click();
settingsTlsCertificatesPageObj.tlsCertificatesView().shouldBe(visible);
}

@Step("Management Service TLS key hash is visible")
public void tlsCertificateHash() {
settingsTlsCertificatesPageObj.certificateHash().shouldBe(visible);
}

@Step("Management Service TLS key hash field is clicked")
public void tlsCertificateHashIsClicked() {
settingsTlsCertificatesPageObj.certificateHash().click();
}

@Step("user is able to view the certificate details")
public void userIsAbleToViewTheCertificate() {
settingsTlsCertificatesPageObj.certificateView.certificateDetails().shouldBe(visible);
}

@Step("Downloading certificate button is enabled")
public void downloadCertificateButton() {
settingsTlsCertificatesPageObj.btnDownloadCertificate().shouldBe(visible);
}

@Step("Downloading certificate button is clicked")
public void downloadCertificateButtonIsClicked() {
final var file = settingsTlsCertificatesPageObj.btnDownloadCertificate().download();
scenarioContext.putStepData(DOWNLOADED_CERTIFICATE, file);
}

@Step("Management Service certificate is successfully downloaded")
public void certificateIsDownloaded() {
final File file = scenarioContext.getStepData(DOWNLOADED_CERTIFICATE);
assertThat(file)
.exists()
.isFile()
.isNotEmpty()
.hasExtension("gz");
}

@Step("Re-create key button is enabled")
public void createCertificateKeyButton() {
settingsTlsCertificatesPageObj.btnCreateKeyCertificate().shouldBe(visible);
}

@Step("Re-create key button is clicked")
public void createCertificateKeyButtonIsClicked() {
settingsTlsCertificatesPageObj.btnCreateKeyCertificate().click();
}

@Step("new key and certificate are successfully created")
public void keyAndCertificateAreCreated() {
commonPageObj.dialog.btnCancel().shouldBe(enabled);
commonPageObj.dialog.btnDelete().shouldBe(enabled).click();

commonPageObj.snackBar.success().shouldBe(visible);
commonPageObj.snackBar.btnClose().click();
}

@Step("Generate CSR is enabled")
public void generateCsrButton() {
settingsTlsCertificatesPageObj.btnCreateCsr().shouldBe(visible);
}

@Step("Generate CSR button is clicked")
public void createCsrButtonIsClicked() {
settingsTlsCertificatesPageObj.btnCreateCsr().click();
}

@Step("new dialog is opened and Enter Distinguished name is asked and value {} is entered")
public void enterDistinguishedName(final String distinguishedName) {
settingsTlsCertificatesPageObj.createCsrDialog.btnGenerateCsr().shouldBe(disabled);
settingsTlsCertificatesPageObj.createCsrDialog.btnCancel().shouldBe(enabled);
vTextField(settingsTlsCertificatesPageObj.createCsrDialog.distinguishedName())
.setValue(distinguishedName);
}

@Step("dialog Generate CSR button is clicked")
public void generateCsrIsClicked() {
final var file = settingsTlsCertificatesPageObj.createCsrDialog.btnGenerateCsr().download();
scenarioContext.putStepData(DOWNLOADED_CSR, file);
}

@Step("generated sign request is downloaded")
public void enterServerCode() {
final File file = scenarioContext.getStepData(DOWNLOADED_CSR);
assertThat(file)
.exists()
.isFile()
.isNotEmpty()
.hasExtension("p10");
}

@Step("Upload certificate is enabled")
public void uploadCertificateButton() {
settingsTlsCertificatesPageObj.btnUploadCertificate().shouldBe(visible);
}

@Step("different management service TLS certificate {} is uploaded")
public void uploadCertificate(String fileName) {
settingsTlsCertificatesPageObj.btnUploadCertificate().click();

commonPageObj.dialog.btnCancel().shouldBe(enabled);
commonPageObj.dialog.btnSave().shouldBe(disabled);
commonPageObj.inputFile().uploadFromClasspath("files/certificates/" + fileName);
commonPageObj.dialog.btnSave().shouldBe(enabled).click();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ public SelenideElement settingsTab() {
public SelenideElement apiKeysTab() {
return $x("//*[@data-test='apikeys-tab-button']");
}

public SelenideElement tlsCertificatesTab() {
return $x("//*[@data-test='tlscertificates-tab-button']");
}
}

public class Dialog {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* The MIT License
* <p>
* Copyright (c) 2019- Nordic Institute for Interoperability Solutions (NIIS)
* Copyright (c) 2018 Estonian Information System Authority (RIA),
* Nordic Institute for Interoperability Solutions (NIIS), Population Register Centre (VRK)
* Copyright (c) 2015-2017 Estonian Information System Authority (RIA), Population Register Centre (VRK)
* <p>
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* <p>
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* <p>
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.niis.xroad.cs.test.ui.page;

import com.codeborne.selenide.SelenideElement;

import static com.codeborne.selenide.Selenide.$x;

public class SettingsTlsCertificatesPageObj {

public final CertificateViewPageObj certificateView = new CertificateViewPageObj();
public final CreateCsrDialog createCsrDialog = new CreateCsrDialog();

public SelenideElement tlsCertificatesView() {
return $x("//div[@data-test='tls-certificates-view']");
}

public SelenideElement certificateHash() {
return $x("//div[@data-test='view-management-service-certificate']");
}

public SelenideElement btnDownloadCertificate() {
return $x("//button[@data-test='download-management-service-certificate']");
}

public SelenideElement btnUploadCertificate() {
return $x("//button[@data-test='upload-management-service-certificate']");
}

public SelenideElement btnCreateKeyCertificate() {
return $x("//button[@data-test='management-service-certificate-generateKey']");
}

public SelenideElement btnCreateCsr() {
return $x("//button[@data-test='management-service-certificate-generateCsr']");
}

public static class CreateCsrDialog {
public SelenideElement distinguishedName() {
var xpath = "//div[@data-test='enter-distinguished-name']";
return $x(xpath);
}

public SelenideElement btnGenerateCsr() {
var xpath = "//button[@data-test='dialog-save-button']";
return $x(xpath);
}

public SelenideElement btnCancel() {
var xpath = "//button[@data-test='dialog-cancel-button']";
return $x(xpath);
}

public SelenideElement dialog() {
var xpath = "//div[@data-test='dialog-simple']";
return $x(xpath);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
@CentralServer
Feature: 0860 - CS: Settings -> TLS Certificates

Background:
Given CentralServer login page is open
And Page is prepared to be tested
And User xrd logs in to CentralServer with password secret
And CentralServer Settings tab is selected

Scenario: Management Service TLS certificate is visible and all buttons are enabled
Given TLS Certificates sub-tab is selected
And Management Service TLS key hash is visible
And Downloading certificate button is enabled
And Re-create key button is enabled
And Generate CSR is enabled
And Upload certificate is enabled

Scenario: Management Service TLS certificate can be viewed
Given TLS Certificates sub-tab is selected
When Management Service TLS key hash field is clicked
Then user is able to view the certificate details

Scenario: Management Service TLS certificate can be downloaded
Given TLS Certificates sub-tab is selected
When Downloading certificate button is clicked
Then Management Service certificate is successfully downloaded

Scenario: Management Service TLS key and certificate can be re-created
Given TLS Certificates sub-tab is selected
When Re-create key button is clicked
Then new key and certificate are successfully created

Scenario: Management Service TLS certificate sign request can be generated
Given TLS Certificates sub-tab is selected
When Generate CSR button is clicked
Then new dialog is opened and Enter Distinguished name is asked and value CN=cs is entered
When dialog Generate CSR button is clicked
Then generated sign request is downloaded

Scenario: Management Service TLS certificate with different key can't be uploaded
Given TLS Certificates sub-tab is selected
When different management service TLS certificate management-service-new.crt is uploaded
Then error: "The imported certificate does not match the TLS key" was displayed
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
-----BEGIN CERTIFICATE-----
MIIEXzCCAkegAwIBAgIBFDANBgkqhkiG9w0BAQsFADBbMQswCQYDVQQGEwJGSTEU
MBIGA1UECgwLWC1Sb2FkIFRlc3QxGjAYBgNVBAsMEVgtUm9hZCBUZXN0IENBIE9V
MRowGAYDVQQDDBFYLVJvYWQgVGVzdCBDQSBDTjAeFw0yMzEyMDMxNzI1NDJaFw00
MzExMjgxNzI1NDJaMA0xCzAJBgNVBAMTAmNzMIIBIjANBgkqhkiG9w0BAQEFAAOC
AQ8AMIIBCgKCAQEA5jc6BLUa370inDJUxe6vpjO3y8RkXth/CTujNWUW4DPOEzyG
70cvx8cFzE0EvDkZXV2SmgXs1JD+co+ofsjlzYAAGQ9aXGJFgpGisUUBkwDdxHhz
LoESjLcx9kddVWowTiKOevDz45++1WMFKq/xqxz0q5Ve0moJgGTTfz1m2d+zHmML
M/uVyq8bjN7ByoTC/h4ASovdpLB8Nf4LRQ2UGW0PpUDYeU6aSZTabhw3mNT1SUEN
eyqG0QjgI+e66Y+s63bDcMj+TQEVDW8Qtt2yHFLhlmxulljeNHkFHUgFos0XiqrB
7sbI9JFRHcmCiwqDBs+C/Tr5sODbvfG+gS0kiwIDAQABo3wwejAJBgNVHRMEAjAA
MA4GA1UdDwEB/wQEAwIDuDAdBgNVHSUEFjAUBggrBgEFBQcDAgYIKwYBBQUHAwEw
HQYDVR0OBBYEFEOCAOJH47NPD0dFmF1nR1ZvU571MB8GA1UdIwQYMBaAFM51u32T
zwxNT6vzD/4qyBUgKlCcMA0GCSqGSIb3DQEBCwUAA4ICAQA/DTts/NYUSlZstw1o
0bQ/vUuTMiI4HX+0KzFBZE1hN122ZnRMnSOWdntz3hfFXQceJXOEzME70uLsSd2B
vI5SanKrB6g6squTDXfW26c+uI1p4KuUAGDt3/nhEOHjljjKpIvmZD7/O4mSOJBq
i96rLDR3qbf4rpJDrV8CVOBy3/0pWFn4QgLcMcG6HcJAYDZqHKiz6y93ytiIkLp6
+wa68ouBwFFuFdm9wcDhznmElU49Pk0RqfmlxBbOANvNPmh41F+WuCgVund5NuaF
aS1rWb4x6IjSvNvln8Y0kFEq7YkbMKMUxBfjhAhP6VQKQ4FvULe5Z+DfV98xeNuI
j9DMS0psuzq5p0UzlL6Sa6eOwKY7vJIjyT32mLvYHvihR0RkjEm9n6nd8jYgFOpn
rEMMaV2gIoJIje9/eVAVfxr18FGrDL5CQrZPCorQjcQPShKRQebupkvkuI06GWHB
nKuXCE52qokrv51V8gbWW6z4MnvNfm1hMViEDpOfjYArs2rsP8FCiTD0A+qeOn9T
uPvdLD9ht5itQx/hEYTjngH6gusr+s8SOlAZa7Ri9TQW2qTmsxmrPmMuqM8jL4PV
a0QvYbkZ203CEEnxOt/gebVSJoYLzzXiPBMQzQQGdk4K+HwyqC5Mzw9NRwK8UtWq
qnkhKmVxChoZFCAVXkBDKDI8Hw==
-----END CERTIFICATE-----
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,23 @@
<xrd-simple-dialog
:disable-save="distinguishedName.length === 0"
:loading="loading"
title="systemSettings.tlsCertificates.managementService.generateCsr.title"
title="tlsCertificates.managementService.generateCsr.title"
save-button-text="action.generateCsr"
cancel-button-text="action.cancel"
@cancel="cancel"
@save="generateCsr"
>
<template #text>
{{ $t('systemSettings.tlsCertificates.managementService.generateCsr.content') }}
{{ $t('tlsCertificates.managementService.generateCsr.content') }}
</template>
<template #content>
<v-text-field
v-model="distinguishedName"
variant="outlined"
autofocus
:placeholder="$t('systemSettings.tlsCertificates.managementService.generateCsr.example')"
:label="$t('systemSettings.tlsCertificates.managementService.generateCsr.distinguishedName')"
data-test="enter-distinguished-name"
:placeholder="$t('tlsCertificates.managementService.generateCsr.example')"
:label="$t('tlsCertificates.managementService.generateCsr.distinguishedName')"
>
</v-text-field>
</template>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
-->
<template>
<xrd-simple-dialog
title="systemSettings.tlsCertificates.managementService.generateKey.title"
title="tlsCertificates.managementService.generateKey.title"
save-button-text="action.confirm"
:show-close="false"
:loading="loading"
Expand All @@ -35,10 +35,10 @@
>
<template #content>
<p data-test="generate-tls-and-certificate-dialog-explanation-text">
{{ $t('systemSettings.tlsCertificates.managementService.generateKey.explanation') }}
{{ $t('tlsCertificates.managementService.generateKey.explanation') }}
</p>
<p data-test="generate-tls-and-certificate-dialog-confirmation-text">
{{ $t('systemSettings.tlsCertificates.managementService.generateKey.confirmation') }}
{{ $t('tlsCertificates.managementService.generateKey.confirmation') }}
</p>
</template>
</xrd-simple-dialog>
Expand Down Expand Up @@ -68,7 +68,7 @@ export default defineComponent({
.generateKey()
.then(() => {
this.showSuccess(
this.$t('systemSettings.tlsCertificates.managementService.generateKey.success'),
this.$t('tlsCertificates.managementService.generateKey.success'),
);
this.$emit(Event.Confirm);
})
Expand Down
Loading

0 comments on commit 917d44c

Please sign in to comment.