Skip to content

Commit e40cc98

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

File tree

3 files changed

+162
-11
lines changed

3 files changed

+162
-11
lines changed
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
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+
shell: /usr/bin/bash -ie {0}
106+
run: |
107+
set -ex
108+
echo 'INTEGRATION_TEST' > ./secret_data
109+
result="$(./nc-secrets -k create -t 'integration-test' http://localhost:8080 admin ./secret_data <<<"password")"
110+
echo "${result}"
111+
112+
- name: Report
113+
if: always()
114+
run: |
115+
tail ./php.log
116+
117+
if ${{ steps.integration_test.result != 'success' }}; then exit 1; fi
118+
119+
summary:
120+
runs-on: ubuntu-latest
121+
needs: integration-test-cli
122+
if: always()
123+
name: integration-test-summary
124+
125+
steps:
126+
- name: 'Report'
127+
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: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,37 @@
44
import readline from 'node:readline'
55
import process from 'process'
66

7-
const rl = readline.createInterface({
8-
input: process.stdin,
9-
output: process.stdout,
10-
})
11-
export const prompt = (query: string) => new Promise<string>((resolve) => rl.question(query,
12-
(answer) => {
13-
rl.close()
14-
resolve(answer)
15-
})
16-
)
7+
// const rl = readline.createInterface({
8+
// input: process.stdin,
9+
// output: process.stdout,
10+
// terminal: false,
11+
// })
12+
// export const prompt = (query: string) => new Promise<string>((resolve) => {
13+
// console.log("prompting...")
14+
//
15+
// if (!process.stdin.isTTY) {
16+
// process.stdin._read()
17+
// }
18+
//
19+
// return rl.question(query,
20+
// (answer) => {
21+
// rl.close()
22+
// resolve(answer)
23+
// })
24+
// }
25+
// )
26+
27+
export async function prompt(query: string){
28+
29+
process.stderr.write(query)
30+
31+
let data = ""
32+
for await (const chunk of process.stdin) {
33+
data += chunk;
34+
}
35+
36+
37+
// process all the data and write it back to stdout
38+
39+
return data.replace(/\n$/, "")
40+
}

0 commit comments

Comments
 (0)