Skip to content

Initial draft PR to introduce Integration Tests for SAML auth flow#1044

Closed
devardee wants to merge 9 commits intoopensearch-project:mainfrom
devardee:saml_integ_tests
Closed

Initial draft PR to introduce Integration Tests for SAML auth flow#1044
devardee wants to merge 9 commits intoopensearch-project:mainfrom
devardee:saml_integ_tests

Conversation

@devardee
Copy link
Contributor

Description

Integration test to validate SAML flow, this is a draft PR. Integ tests are based on selenium web driver.

Category

Check List

  • New functionality includes testing
  • New functionality has been documented
  • Commits are signed per the DCO using --signoff

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@devardee devardee requested a review from a team July 28, 2022 14:48

// Create certificate pair on the fly and pass it to runServer
runServer({
acsUrl: 'http://localhost:5601/_opendistro/_security/saml/acs',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it possible to run idp server with acs /_plugins/_security/saml/acs? or will it be covered in next iteration of this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did not understand, can you please explain?

{
path: '/_plugins/_security/saml/acs',
// need to change to /_opendistro to execute the tests.
path: '/_opendistro/_security/saml/acs',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way you can test both endpoints or just the new one?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can ignore this, since you had already merged this change

Copy link
Member

@peternied peternied left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really great work, I've added a couple of comments, but its looking very close. I noticed there were 4 scenarios called out in the saml tests but I only see 2 tests cases, were you working on implementing all 4?

Comment on lines +21 to +22
//for now only run saml integration test.
testMatch: ['**/test/jest_integration/**/saml_auth.tests.ts'],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert

Note you can also use use test.only for quickly focusing on a single test, see https://devhints.io/jest Focusing tests

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I will revert this config change


});

function sleepFor(sleepDuration: number) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't look used,
IMO this is the better mechanism https://decipher.dev/30-seconds-of-typescript/docs/sleep/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, will remove this

@@ -0,0 +1,28 @@
-----BEGIN PRIVATE KEY-----
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see a reference, can we remove both checked in certs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the IDP server uses this certificate to generate idp's metadata, we can acutally generate these certificates on the fly, I have just hardcoded for now

"lint:es": "node ../../scripts/eslint",
"lint:style": "node ../../scripts/stylelint",
"lint": "yarn run lint:es && yarn run lint:style",
"pretest:jest_server": "node ./test/jest_integration/runIdpServer.js &",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be started during saml_auth.tests.ts start up so it only impacts those tests it applies to?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, this can be done, will only start idp server for the saml tests

}
);
} catch (error) {
console.log('Got an error!!');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

include that error in the logged output

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure

await driver
.wait(
until.elementsLocated(
By.xpath("/html/body/div[1]/div/div/div/div[2]/div/main/div[1]/span/button/span")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way this can be found by id that would be cleaner?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, I will need to look at the DOM to see for ID's

@devardee
Copy link
Contributor Author

devardee commented Aug 2, 2022

Yes, I will add test to capture all the scenarios

Copy link
Member

@peternied peternied left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any pushed changes, please update the PR so it can be reviewed.

@devardee
Copy link
Contributor Author

devardee commented Aug 3, 2022

sure will update the PR, btw can we merge this PR #1001 ?

@peternied
Copy link
Member

@devardee I haven't seen any updates on this PR - could you let us know what you thoughts are? When I attempt to run the code locally I get an error that there is no gecko driver for firefox present, so it seems like there are some additional fundamentals that are missing.

  ● start OpenSearch Dashboards server › Login to app/dev_tools#/console when SAML is enabled

    The geckodriver executable could not be found on the current PATH. Please download the latest version from https://github.com/mozilla/geckodriver/releases/ and ensure it can be found on your PATH.

      87 |     // initWebDriver()
      88 |
    > 89 |     driver = new Builder().forBrowser('firefox').setFirefoxOptions({addArguments: '--headless'}).build();
         |                                                                                                  ^
      90 |
      91 |     await wreck.patch(
      92 |       'https://localhost:9200/_plugins/_security/api/rolesmapping/all_access',

      at findGeckoDriver (plugins/security-dashboards-plugin/node_modules/selenium-webdriver/firefox.js:463:11)
      at new ServiceBuilder (plugins/security-dashboards-plugin/node_modules/selenium-webdriver/firefox.js:556:22)
      at Function.createSession (plugins/security-dashboards-plugin/node_modules/selenium-webdriver/firefox.js:612:21)
      at createDriver (plugins/security-dashboards-plugin/node_modules/selenium-webdriver/index.js:146:33)
      at Builder.build (plugins/security-dashboards-plugin/node_modules/selenium-webdriver/index.js:682:16)
      at Object.<anonymous> (plugins/security-dashboards-plugin/test/jest_integration/saml_auth.test.ts:89:98)

@devardee
Copy link
Contributor Author

I will resume my work on this, I am hoping to complete (refactor + adding additional test cases) by end of next week.

@peternied to run the selenium tests locally you need to install the geckodriver and add it to your PATH env variable. To run this test in CI, I was thinking of installing gecko driver via setup script and run it in Headless mode, is this the correct approach ?

@peternied
Copy link
Member

I was thinking of installing gecko driver via setup script and run it in Headless mode

Please make sure you document what it takes to run the tests, as some folks are on mac/windows/linux - platform agnostic would be the best if there is an easy way to incorporate. No matter the local steps, please also update the ci.yml workflow to make sure the GitHub Action is setup with whatever it will need to run the tests.

@peternied
Copy link
Member

@devardee I haven't seen any updates, anything that you need help with?

devardee and others added 5 commits August 30, 2022 14:02
Signed-off-by: Deepak Devarakonda <devardee@amazon.com>
Signed-off-by: Aniketh Jain <anijainc@amazon.com>
Signed-off-by: Aniketh Jain <anijainc@amazon.com>
Signed-off-by: Aniketh Jain <anijainc@amazon.com>
Signed-off-by: Aniketh Jain <anijainc@amazon.com>
This was referenced Aug 30, 2022
@devardee
Copy link
Contributor Author

devardee commented Sep 1, 2022

Closing this PR in favor of #1088

@devardee devardee closed this Sep 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants