Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 49 additions & 10 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ on:
branches: [ main ]

jobs:
ci:

deploy:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [24.x]
Expand All @@ -29,12 +27,9 @@ jobs:
- run: npm ci
- run: npm run lint:ci

- name: Create local config for tests
- name: Create local config for the app to connect to couchdb service in the container
run: |
echo 'module.exports = { usersDbConnection: { url: "http://localhost:5984" }};' > config/local.js

- name: Run Integration tests
run: DEBUG=replay* npm run coverage || echo 'Test run failed replay no longer is working with latest nano which uses node fetch'
echo 'module.exports = { usersDbConnection: { url: "http://couchdb:5984" }};' > config/local.js

- name: Start docker compose services
run: docker compose up -d && sleep 5
Expand All @@ -48,18 +43,62 @@ jobs:
SOURCE_URL: ${{ secrets.SOURCE_URL }}
DEBUG: 'none'

- name: Run E2E tests
run: REPLAY=bloody npm run test:deprecated
- name: Run E2E tests against the container app
run: REPLAY=bloody URL=https://localhost:3183 npm run test:deprecated || echo 'Test run failed when trying to use the deployed auth app'
env:
SOURCE_URL: ${{ secrets.SOURCE_URL }}
DEBUG: 'none'

- name: Show docker compose logs
if: success() || failure()
run: docker compose logs --no-color --timestamps || true

integration-tests:
runs-on: ubuntu-latest
needs: [deploy]
steps:
- uses: actions/checkout@v6
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v6
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- name: Create local config for tests to use the couchdb from the container
run: |
echo 'module.exports = { usersDbConnection: { url: "http://localhost:5984" }};' > config/local.js
- name: Run Integration tests
run: DEBUG=replay* npm run coverage || echo 'Test run failed replay no longer is working with latest nano which uses node fetch'
- name: Run integration tests using the app with local couchdb
run: REPLAY=bloody npm run test:deprecated
env:
SOURCE_URL: ${{ secrets.SOURCE_URL }}
DEBUG: 'none'
- name: Upload coverage report
uses: actions/upload-artifact@v5
if: success() || failure()
with:
name: coverage
path: coverage/
retention-days: 3
- name: Coveralls
if: success() || failure()
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}

ui-tests:
runs-on: ubuntu-latest
needs: [deploy]
steps:
- uses: actions/checkout@v6
with:
sparse-checkout:: |
package.json
- name: Use Node.js 24.x
uses: actions/setup-node@v6
with:
node-version: 24.x
cache: 'npm'
- name: Run UI tests
run: npm run test:ui
timeout-minutes: 5
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ RUN ls -alt; \
ls config/local.js || echo " config/local.js is required to be able to run the tests against deployed couchdb"

ENV DEBUG="*,-express*"
ENV NODE_ENV=beta
ENV NODE_ENV=localhost

EXPOSE 3183

Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ services:
environment:
- COUCHDB_USER=admin
- COUCHDB_PASSWORD=none
app:
auth_app:
depends_on:
- couchdb
build:
Expand Down
2 changes: 1 addition & 1 deletion etc/local.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ credentials = true
attachments_enable = true
; https://docs.couchdb.org/en/stable/cve/2021-38295.html
; use nginx instead to allow only signed couchapps when on deployed server
attachments_header_value = "child-src 'self' data: blob:; default-src 'self'; img-src 'self' data: https://secure.gravatar.com; font-src 'self'; script-src 'self' 'unsafe-eval'; style-src 'self' 'unsafe-inline';"
attachments_header_value = "child-src 'self' data: blob:; default-src 'self'; connect-src 'self' https://corpusdev.example.com https://localhost:3183 https://www.google-analytics.com; img-src 'self' data: https://secure.gravatar.com; font-src 'self' https://themes.googleusercontent.com; script-src 'self' 'unsafe-eval' https://www.google-analytics.com; style-src 'self' 'unsafe-inline';"

[couchdb]
single_node=true
Expand Down
8 changes: 5 additions & 3 deletions lib/corpus.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { couchKeys } = require('config');
const { couchKeys, usersDbConnection } = require('config');
const debug = require('debug')('lib:corpus');
const url = require('url');
const { Corpus } = require('fielddb/api/corpus/Corpus');
Expand All @@ -16,7 +16,7 @@ const contributor = 'writer';
const admin = 'admin';

// Only create users on the same server.
const parsed = url.parse('http://localhost:5984');
const parsed = url.parse(usersDbConnection.url);
const couchConnectUrl = `${parsed.protocol}//${couchKeys.username}:${couchKeys.password}@${parsed.host}`;
debug('Using corpus url: ', couchConnectUrl);

Expand Down Expand Up @@ -377,6 +377,7 @@ function createNewCorpus({
// }
// });
return newDatabase.bulk({
// TODO this might be using the connction rather than the config's connection about where to write the docs
docs: docsNeededForAProperFieldDBCorpus,
});
})
Expand Down Expand Up @@ -421,7 +422,8 @@ function createNewCorpus({
const err = {
...errOriginal,
};
debug('createNewCorpus', err);
// eslint-disable-next-line no-console
console.error('createNewCorpus', err);
// Clean the error of couchdb leaks
delete err.request;
delete err.headers;
Expand Down
2 changes: 1 addition & 1 deletion nyc.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ module.exports = {
functions: 65,
lines: 76,
statements: 76,
reporter: ['text', 'lcov'],
reporter: ['html', 'text', 'lcov'],
};
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@
},
"scripts": {
"docker:build": "docker build -t fielddb-auth .",
"docker:test": "echo 'module.exports = { usersDbConnection: { url: \"http://localhost:5984\" } };' > config/local.js && docker compose up -d && sleep 3 && docker compose logs && npm run setup && npm run test:deprecated",
"docker:test:no-cache": "echo 'module.exports = { usersDbConnection: { url: \"http://localhost:5984\" } };' > config/local.js && docker compose build --no-cache && docker compose up -d && sleep 15 && docker compose logs && npm run setup && npm run test:deprecated",
"test:e2e": "echo 'module.exports = { usersDbConnection: { url: \"http://couchdb:5984\" } };' > config/local.js && docker compose up -d && sleep 3 && docker compose logs && npm run setup && npm run test:deprecated",
"docker:test:no-cache": "echo 'module.exports = { usersDbConnection: { url: \"http://couchdb:5984\" } };' > config/local.js && docker compose build --no-cache && docker compose up -d && sleep 15 && docker compose logs && npm run setup && npm run test:deprecated",
"coverage": "NODE_ENV=test BUNYAN_LOG_LEVEL=FATAL nyc npm test",
"lint": "eslint ",
"lint:ci": "eslint .",
Expand All @@ -74,7 +74,7 @@
"test:deprecated": "DEBUG=${DEBUG:-lib:user} REPLAY=bloody NODE_TLS_REJECT_UNAUTHORIZED=0 nyc mocha --timeout 25000 test/routes/deprecated-spec.js",
"test:fielddb": "NODE_ENV=localhost jasmine-node node_modules/fielddb/tests",
"test:production": "ls config/production.js",
"test:ui": "git clone https://github.com/FieldDB/FieldDB.git; cd FieldDB/test-e2e && npm install && npx playwright install chromium && BASE_URL=${BASE_URL:-https://localhost:6984} BASE_PATH=${BASE_PATH:-/prototypedev/_design/prototype} DEBUG=${DEBUG:-none} npm run test -- --retries=0 --project=Chromium register",
"test:ui": "git clone --filter=blob:none --no-checkout https://github.com/FieldDB/FieldDB.git; cd FieldDB; git sparse-checkout set test-e2e; git checkout HEAD; cd test-e2e && npm install && npx playwright install chromium && BASE_URL=${BASE_URL:-https://localhost:6984} BASE_PATH=${BASE_PATH:-/prototypedev/_design/prototype} DEBUG=${DEBUG:-none} npm run test -- --retries=0 --project=Chromium register",
"watch": "nodemon ./bin/www.js"
},
"license": "Apache-2.0"
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/replay/localhost-5984/176495332887018347
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
GET /prototype/_design/prototype
GET /prototypedev/_design/prototype
accept-encoding: gzip, deflate
accept: application/json
authorization: Basic YWRtaW46bm9uZQ==
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/replay/localhost-5984/176522423245686959
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
GET /prototype/_design/prototype/user.html
GET /prototypedev/_design/prototype/user.html
accept-encoding: gzip, deflate
authorization: Basic YWRtaW46bm9uZQ==

Expand Down
2 changes: 1 addition & 1 deletion test/integration/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ describe('install', () => {
* and the app expects and requires https
*/
it('should replicate prototype', () => {
const dbnameToReplicate = 'prototype';
const dbnameToReplicate = 'prototypedev';

return supertest(destination)
.post('/_replicate')
Expand Down
2 changes: 1 addition & 1 deletion test/routes/deprecated-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('/ deprecated', () => {
// eslint-disable-next-line no-underscore-dangle
debug('before replay localhosts', replay._localhosts);

return supertest(config.usersDbConnection.url)
return supertest(config.usersDbConnection.url.replace('://couchdb', '://localhost'))
.get('/')
.set('Accept', 'application/json')
.then((res) => {
Expand Down