ui5-community / ui5-ecosystem-showcase

A repository showcasing the UI5 tooling extensibility to combine OSS tools for UI5 application development.
https://ui5-community.github.io/ui5-ecosystem-showcase/
Other
194 stars 94 forks source link

[ui5-middleware-onelogin] Login with SAP Passport Certificate #1078

Open marianfoo opened 2 months ago

marianfoo commented 2 months ago

Since Playwright Version 1.46 it is possible to provide a certificate to login.
It would make sense to integrate this into the login middleware.

In a minimal sample i was able to login with my SAP Passport X.509 Certificate in pfx format:

playwright.config.ts

import { defineConfig } from '@playwright/test';

export default defineConfig({
  use: {
    headless: false, // Set to true if you want headless mode
    viewport: { width: 1280, height: 720 },
    ignoreHTTPSErrors: false,
    clientCertificates: [
    {
        origin: 'https://accounts.sap.com',
        pfxPath: 'sap.pfx',
        passphrase: 'XXX',       // Password for the .pfx file
      }
    ]
  },
});

sap-login.spec.ts

import { test, expect } from '@playwright/test';

test('Login to SAP BTP Cockpit with client certificate', async ({ page }) => {
  // Go to the SAP BTP Cockpit URL
  await page.goto('https://emea.cockpit.btp.cloud.sap/cockpit#/');

  // Wait for the login page to load (adjust the selector based on the actual login form structure)
  await expect(page).toHaveURL('https://emea.cockpit.btp.cloud.sap/cockpit#/');

  // You can add further checks to ensure successful login based on page content, URL change, etc.
  // add 10 seconds wait
  await page.waitForTimeout(10000);

  // Take a screenshot of the page
  await page.screenshot({ path: 'screenshot.png' });

});

package.json

{
  "name": "sap-certificate-auth",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@playwright/test": "^1.48.0-alpha-2024-09-13",
    "@types/node": "^22.5.4",
    "typescript": "^5.6.2"
  }
}