Skip to content

Commit

Permalink
Try to get token using python script
Browse files Browse the repository at this point in the history
  • Loading branch information
soapy1 committed Feb 12, 2025
1 parent f6e0194 commit b1079d1
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 7 deletions.
10 changes: 3 additions & 7 deletions .github/workflows/test_local_integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -175,16 +175,12 @@ jobs:
- name: Get conda store token from login
id: conda-store-token
env:
CONDA_STORE_BASE_URL: https://${{ steps.init.outputs.domain }}
BASE_URL: ${{ steps.init.outputs.domain }}
KEYCLOAK_USERNAME: ${{ env.TEST_USERNAME }}
KEYCLOAK_PASSWORD: ${{ env.TEST_PASSWORD }}
working-directory: ${{ steps.init.outputs.directory }}
run: |
echo "${KEYCLOAK_USERNAME}"
LOGIN_URL=$(curl -c /tmp/nebari-session --insecure -Ls ${CONDA_STORE_BASE_URL}/conda-store/login/\?next= | grep auth/realms/nebari/login-actions/authenticate | grep -oP '(?<=action=")([^"]+)' | sed 's/\&amp\;/\&/g')
curl -X POST --insecure -b /tmp/nebari-session -c /tmp/conda-store-cookie -H "Content-Type: application/x-www-form-urlencoded" --data '{"credentialId":"", "username": "test-user", "password": "P@sswo3d"}' $LOGIN_URL
curl --insecure -b /tmp/conda-store-cookie ${CONDA_STORE_BASE_URL}/conda-store/api/v1/permission/ | jq
echo "CONDA_STORE_TOKEN=$(curl --insecure -L -X POST -b /tmp/conda-store-cookie ${CONDA_STORE_BASE_URL}/conda-store/api/v1/token | jq --raw-output .data.token)" >> "$GITHUB_OUTPUT"
ls
echo "CONDA_STORE_TOKEN=$(python scripts/get_conda_store_token.py)" >> "$GITHUB_OUTPUT"
- name: Run conda-store-server user_journey tests
env:
Expand Down
40 changes: 40 additions & 0 deletions scripts/get_conda_store_token.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import re
import os
import requests


def get_conda_store_session_token(username, password, nebari_hostname):
"""Log into conda-store using the test account and get session"""
session = requests.Session()
r = session.get(
f"https://{nebari_hostname}/conda-store/login/?next=", verify=False
)
auth_url = re.search('action="([^"]+)"', r.content.decode("utf8")).group(1)
response = session.post(
auth_url.replace("&amp;", "&"),
headers={"Content-Type": "application/x-www-form-urlencoded"},
data={
"username": username,
"password": password,
"credentialId": "",
},
verify=False,
)
assert response.status_code == 200

token = session.cookies.get("conda-store-auth")
response = requests.get(
f"https://{nebari_hostname}/conda-store/api/v1/permission/",
headers={"Authorization": f"Bearer {token}"},
verify=False,
)
assert response.status_code == 200

return token

if __name__ == "__main__":
username = os.environ.get("KEYCLOAK_USERNAME")
password = os.environ.get("KEYCLOAK_PASSWORD")
url = os.environ.get("BASE_URL")
token = get_conda_store_session_token(username, password, url)
print(token)

0 comments on commit b1079d1

Please sign in to comment.