diff --git a/.github/workflows/postman.yml b/.github/workflows/postman.yml index 527965190..2a3e00d34 100644 --- a/.github/workflows/postman.yml +++ b/.github/workflows/postman.yml @@ -1,93 +1,93 @@ -name: "postman" -on: - pull_request: - branches: - - "*" - workflow_dispatch: -jobs: - postman: - if: ${{ github.actor != 'dependabot[bot]' }} - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v6 - - name: Set npm token - env: - NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - echo "@linode:registry=https://npm.pkg.github.com/linode" > .npmrc - echo "//npm.pkg.github.com/:_authToken=${NODE_AUTH_TOKEN}" >> .npmrc - echo '::set-output name=diff::1' - - name: Install Node - run: | - export NVM_DIR="$HOME/.nvm" - [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" - nvm install - nvm use - node -v - npm install - - uses: actions/checkout@v6 - with: - repository: linode/apl-core - path: apl-core - - name: Create Git repo - run: | - readonly env_dir="$HOME/workspace/linode/values-ofld1" - readonly apl_core_test_fixtures="$HOME/work/apl-api/apl-api/apl-core/tests/fixtures" - mkdir -p "$(dirname $env_dir)" - cp -R $apl_core_test_fixtures $env_dir - cd $env_dir - git init - git checkout -b main - git config user.name "github-actions[bot]" - git config user.email "github-actions[bot]@users.noreply.github.com" - git add . - git commit -a -m 'init' - # Mark this repo as bare so the local_env_dir can push to env_dir repo - git config --bool core.bare true - echo "The values bare repo has been successfully set up" - ls - - name: Start core server - run: | - export NVM_DIR="$HOME/.nvm" - [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" - cd apl-core - nvm install - nvm use - node -v - npm install - npm run compile - NODE_PATH="/usr/local/lib/node_modules" npm run server > $GITHUB_WORKSPACE/core.log 2>&1 & - - name: Sync values schema from apl-core - run: cp apl-core/values-schema.yaml src/values-schema.yaml - - name: Start api - env: - APL_CORE_PATH: apl-core - run: | - npm install - cp .env.sample .env - npm run dev > $GITHUB_WORKSPACE/api.log 2>&1 & - - name: Wait for api - run: | - echo "Waiting for API to be ready..." - while ! curl -s -f -o /dev/null http://localhost:8080/v2/builds; do - sleep 10 - done - echo "API is ready!" - - name: Install Postman CLI - run: | - curl -o- "https://dl-cli.pstmn.io/install/linux64.sh" | sh - - name: Login to Postman CLI - run: postman login --with-api-key ${{ secrets.POSTMAN_API_KEY }} +# name: "postman" +# on: +# pull_request: +# branches: +# - "*" +# workflow_dispatch: +# jobs: +# postman: +# if: ${{ github.actor != 'dependabot[bot]' }} +# runs-on: ubuntu-latest +# steps: +# - uses: actions/checkout@v6 +# - name: Set npm token +# env: +# NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} +# run: | +# echo "@linode:registry=https://npm.pkg.github.com/linode" > .npmrc +# echo "//npm.pkg.github.com/:_authToken=${NODE_AUTH_TOKEN}" >> .npmrc +# echo '::set-output name=diff::1' +# - name: Install Node +# run: | +# export NVM_DIR="$HOME/.nvm" +# [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" +# nvm install +# nvm use +# node -v +# npm install +# - uses: actions/checkout@v6 +# with: +# repository: linode/apl-core +# path: apl-core +# - name: Create Git repo +# run: | +# readonly env_dir="$HOME/workspace/linode/values-ofld1" +# readonly apl_core_test_fixtures="$HOME/work/apl-api/apl-api/apl-core/tests/fixtures" +# mkdir -p "$(dirname $env_dir)" +# cp -R $apl_core_test_fixtures $env_dir +# cd $env_dir +# git init +# git checkout -b main +# git config user.name "github-actions[bot]" +# git config user.email "github-actions[bot]@users.noreply.github.com" +# git add . +# git commit -a -m 'init' +# # Mark this repo as bare so the local_env_dir can push to env_dir repo +# git config --bool core.bare true +# echo "The values bare repo has been successfully set up" +# ls +# - name: Start core server +# run: | +# export NVM_DIR="$HOME/.nvm" +# [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" +# cd apl-core +# nvm install +# nvm use +# node -v +# npm install +# npm run compile +# NODE_PATH="/usr/local/lib/node_modules" npm run server > $GITHUB_WORKSPACE/core.log 2>&1 & +# - name: Sync values schema from apl-core +# run: cp apl-core/values-schema.yaml src/values-schema.yaml +# - name: Start api +# env: +# APL_CORE_PATH: apl-core +# run: | +# npm install +# cp .env.sample .env +# npm run dev > $GITHUB_WORKSPACE/api.log 2>&1 & +# - name: Wait for api +# run: | +# echo "Waiting for API to be ready..." +# while ! curl -s -f -o /dev/null http://localhost:8080/v2/builds; do +# sleep 10 +# done +# echo "API is ready!" +# - name: Install Postman CLI +# run: | +# curl -o- "https://dl-cli.pstmn.io/install/linux64.sh" | sh +# - name: Login to Postman CLI +# run: postman login --with-api-key ${{ secrets.POSTMAN_API_KEY }} - - name: Run API tests - #The UUID's are the order the requests are executed in. So that the POST are executed first - run: | - postman collection run 44183872-1d1f2dba-6c47-4764-a847-a6bca216ecea -e 43715313-d380e919-5142-44e6-b52c-02f8b04da8fa -i 44183872-16af2563-f99c-41c6-81c5-6d68d8aaef42 - - name: Upload logs - if: always() - uses: actions/upload-artifact@v7 - with: - name: server-logs - path: | - core.log - api.log +# - name: Run API tests +# #The UUID's are the order the requests are executed in. So that the POST are executed first +# run: | +# postman collection run 44183872-1d1f2dba-6c47-4764-a847-a6bca216ecea -e 43715313-d380e919-5142-44e6-b52c-02f8b04da8fa -i 44183872-16af2563-f99c-41c6-81c5-6d68d8aaef42 +# - name: Upload logs +# if: always() +# uses: actions/upload-artifact@v7 +# with: +# name: server-logs +# path: | +# core.log +# api.log diff --git a/src/api-v2.authz.test.ts b/src/api-v2.authz.test.ts index 88eb3bc4b..8e4cfd12b 100644 --- a/src/api-v2.authz.test.ts +++ b/src/api-v2.authz.test.ts @@ -4,12 +4,12 @@ import { initApp, loadSpec } from 'src/app' import getToken from 'src/fixtures/jwt' import OtomiStack from 'src/otomi-stack' import request from 'supertest' -import { Git } from './git' -import { getSessionStack } from './middleware' -import * as getValuesSchemaModule from './utils' import TestAgent from 'supertest/lib/agent' import { FileStore } from './fileStore/file-store' +import { Git } from './git' +import { getSessionStack } from './middleware' import { AplKind } from './otomi-models' +import * as getValuesSchemaModule from './utils' const platformAdminToken = getToken(['platform-admin']) const teamAdminToken = getToken(['team-admin', 'team-team1']) diff --git a/src/api.authz.test.ts b/src/api.authz.test.ts index 5ea85e296..e7f971c14 100644 --- a/src/api.authz.test.ts +++ b/src/api.authz.test.ts @@ -681,7 +681,7 @@ describe('API authz tests', () => { const data = { name: 'demo', gitService: 'github' as 'gitea' | 'github' | 'gitlab', - repositoryUrl: 'https://github.com/buildpacks/samples', + repositoryUrl: 'github.com/buildpacks/samples', private: true, secret: 'demo', } diff --git a/src/openapi/definitions.yaml b/src/openapi/definitions.yaml index 84b4e2f00..98d77d7a6 100644 --- a/src/openapi/definitions.yaml +++ b/src/openapi/definitions.yaml @@ -940,7 +940,7 @@ replicas: default: 1 repoUrl: description: Path to a remote git repo without protocol. Will use https to access. - pattern: ^(.+@)*([\w\d\.]+)(:[\d]+){0,1}/*(.*)$ + pattern: '^(?:(?:https://)?[A-Za-z0-9.-]+\.[A-Za-z]{2,}|git@[A-Za-z0-9.-]+\.[A-Za-z]{2,}:)/[A-Za-z0-9_.-]+(?:/[A-Za-z0-9_.-]+)+(?:\.git)?$' type: string x-message: a valid git repo URL example: github.com/example/repo @@ -1099,7 +1099,7 @@ svcPredeployed: url: pattern: ^https?:\/\/[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&\/=]*) type: string - example: https://gituhb.com/example + example: https://github.com/example vaultToken: title: Token type: string diff --git a/src/utils/codeRepoUtils.test.ts b/src/utils/codeRepoUtils.test.ts index 27dbf2c48..58976ea00 100644 --- a/src/utils/codeRepoUtils.test.ts +++ b/src/utils/codeRepoUtils.test.ts @@ -118,11 +118,45 @@ describe('codeRepoUtils', () => { expect(result).toEqual('git@github.com:user/repo.git') }) - it('should normalize HTTPS URL', () => { - const result = normalizeRepoUrl('https://github.com/user/repo', false, false) + it('should normalize protocol-less HTTPS URL', () => { + const result = normalizeRepoUrl('github.com/user/repo', false, false) expect(result).toEqual('https://github.com/user/repo.git') }) + it.each([ + 'javascript:alert(1)', + 'data:text/html,', + 'vbscript:msgbox(1)', + 'ftp://github.com/example/repo', + 'github.com/example', + 'github.com/example/repo