Skip to content

Commit 39852ba

Browse files
committed
CI: Add cli integration test for secret creation/retrieval
1 parent 2d36315 commit 39852ba

File tree

3 files changed

+128
-1
lines changed

3 files changed

+128
-1
lines changed
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
2+
# SPDX-FileCopyrightText: Nextcloud contributors
3+
# SPDX-License-Identifier: AGPL-3.0-or-later
4+
name: Integration Test
5+
6+
on:
7+
pull_request:
8+
push:
9+
branches:
10+
- main
11+
- stable*
12+
tags:
13+
- "v*"
14+
- "test*"
15+
16+
env:
17+
APP_NAME: secrets
18+
19+
jobs:
20+
integration-test-cli:
21+
runs-on: ubuntu-latest
22+
23+
strategy:
24+
matrix:
25+
php-versions: ['8.3']
26+
server-versions: ['v30.0.4', 'v31.0.0beta2']
27+
28+
services:
29+
mysql:
30+
image: mariadb:10.5
31+
ports:
32+
- 4444:3306/tcp
33+
env:
34+
MYSQL_ROOT_PASSWORD: rootpassword
35+
options: --health-cmd="mysqladmin ping" --health-interval 5s --health-timeout 2s --health-retries 5
36+
37+
steps:
38+
- name: Set app env
39+
run: |
40+
# Split and keep last
41+
echo "APP_NAME=secrets" >> $GITHUB_ENV
42+
43+
- name: Enable ONLY_FULL_GROUP_BY MySQL option
44+
run: |
45+
echo "SET GLOBAL sql_mode=(SELECT CONCAT(@@sql_mode,',ONLY_FULL_GROUP_BY'));" | mysql -h 127.0.0.1 -P 4444 -u root -prootpassword
46+
echo "SELECT @@sql_mode;" | mysql -h 127.0.0.1 -P 4444 -u root -prootpassword
47+
48+
- name: Checkout server
49+
uses: actions/checkout@v3
50+
with:
51+
submodules: true
52+
repository: nextcloud/server
53+
ref: ${{ matrix.server-versions }}
54+
55+
- name: Checkout app
56+
uses: actions/checkout@v3
57+
with:
58+
path: apps/${{ env.APP_NAME }}
59+
60+
- name: Set up php ${{ matrix.php-versions }}
61+
uses: shivammathur/setup-php@v2
62+
with:
63+
php-version: ${{ matrix.php-versions }}
64+
tools: phpunit
65+
extensions: mbstring, iconv, fileinfo, intl, mysql, pdo_mysql
66+
coverage: none
67+
68+
- name: Read package.json node and npm engines version
69+
uses: skjnldsv/read-package-engines-version-actions@v1.2
70+
id: versions
71+
with:
72+
fallbackNode: '^12'
73+
fallbackNpm: '^6'
74+
75+
- name: Set up node ${{ steps.versions.outputs.nodeVersion }}
76+
uses: actions/setup-node@v3
77+
with:
78+
node-version: ${{ steps.versions.outputs.nodeVersion }}
79+
80+
- name: Set up bun
81+
uses: oven-sh/setup-bun@v1
82+
83+
- name: Build cli
84+
working-directory: apps/${{ env.APP_NAME }}/cli
85+
run: |
86+
cp ../src/crypto.js ./crypto.import.js
87+
bun install --dev
88+
bun build --compile ./cli.ts --outfile nc-secrets
89+
90+
- name: Set up Nextcloud
91+
env:
92+
DB_PORT: 4444
93+
run: |
94+
mkdir data
95+
./occ maintenance:install --verbose --database=mysql --database-name=nextcloud --database-host=127.0.0.1 --database-port=$DB_PORT --database-user=root --database-pass=rootpassword --admin-user admin --admin-pass password
96+
./occ --version
97+
./occ app:enable ${{ env.APP_NAME }}
98+
99+
- name: Run Nextcloud
100+
run: php -S localhost:8080 > ./php.log 2>&1 &
101+
102+
- name: '[TEST] create and retrieve secret'
103+
working-directory: apps/${{ env.APP_NAME }}/cli
104+
id: integration_test
105+
run: |
106+
set -ex
107+
echo 'INTEGRATION_TEST' > ./secret_data
108+
result="$(./nc-secrets -k create -t 'integration-test' http://localhost:8080 admin ./secret_data <<<"password")"
109+
echo "${result}"
110+
111+
- name: Report
112+
if: always()
113+
run: |
114+
tail ./php.log
115+
116+
if ${{ steps.integration_test.result != 'success' }}; then exit 1; fi
117+
118+
summary:
119+
runs-on: ubuntu-latest
120+
needs: integration-test-cli
121+
if: always()
122+
name: integration-test-summary
123+
124+
steps:
125+
- name: 'Report'
126+
run: if ${{ needs.integration-test-cli.result != 'success' }}; then exit 1; fi

cli/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ contains a Nextcloud password (or app token) for user 'sharer' at a Nextcloud in
5050
you could use the following command:
5151

5252
```sh
53-
./nc-secrets create -t 'My Secret' https://nextcloud.foss sharer "$NC_PASS" ./my-secret <<<"$NC_PASS"
53+
./nc-secrets create -t 'My Secret' https://nextcloud.foss sharer ./my-secret <<<"$NC_PASS"
5454
```
5555

5656
### Retrieve

cli/lib.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import process from 'process'
77
const rl = readline.createInterface({
88
input: process.stdin,
99
output: process.stdout,
10+
terminal: process.stdin.isTTY
1011
})
1112
export const prompt = (query: string) => new Promise<string>((resolve) => rl.question(query,
1213
(answer) => {

0 commit comments

Comments
 (0)