Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "backend runs on 5001 (#495)" #498

Merged
merged 1 commit into from
Apr 16, 2024
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
6 changes: 5 additions & 1 deletion .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ jobs:
- name: Run app and e2e tests
run: |
yarn build
make dev-flask&
[ -d "./venv" ] && . ./venv/bin/activate
export FLASK_APP=./cre.py
export FLASK_CONFIG=development
export INSECURE_REQUESTS=1
FLASK_CONFIG=development flask run &
sleep 20s
yarn test:e2e
4 changes: 3 additions & 1 deletion Dockerfile-dev
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ FROM python:3.11.0 as run
COPY --from=build /code /code
WORKDIR /code
RUN apt update &&\
apt install -y python3-numpy python3-virtualenv python3-pip &&\
apt install -y python3-numpy &&\
pip install virtualenv &&\
make install-deps-python &&\
make install-python

ENTRYPOINT make dev-flask
18 changes: 10 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,18 @@ docker-redis:
start-containers: docker-neo4j docker-redis

start-worker:
. ./venv/bin/activate &&\
FLASK_APP=`pwd`/cre.py python cre.py --start_worker
. ./venv/bin/activate && FLASK_APP=`pwd`/cre.py python cre.py --start_worker

dev-flask:
. ./venv/bin/activate &&\
FLASK_RUN_PORT="5002" INSECURE_REQUESTS=1 FLASK_APP=`pwd`/cre.py FLASK_CONFIG=development flask run
. ./venv/bin/activate && INSECURE_REQUESTS=1 FLASK_APP=`pwd`/cre.py FLASK_CONFIG=development flask run

e2e:
yarn build
make dev-flask&
[ -d "./venv" ] && . ./venv/bin/activate &&\
export FLASK_APP=$(CURDIR)/cre.py &&\
export FLASK_CONFIG=development &&\
export INSECURE_REQUESTS=1 &&\
flask run &
sleep 5
yarn test:e2e
sleep 20
Expand Down Expand Up @@ -64,10 +66,10 @@ docker-prod:
docker build -f Dockerfile -t opencre:$(shell git rev-parse HEAD) .

docker-dev-run:
docker run -it -p 5002:5002 opencre-dev:$(shell git rev-parse HEAD)
docker run -it -p 5000:5000 opencre-dev:$(shell git rev-parse HEAD)

docker-prod-run:
docker run -it -p 5002:5002 opencre:$(shell git rev-parse HEAD)
docker run -it -p 5000:5000 opencre:$(shell git rev-parse HEAD)

lint:
[ -d "./venv" ] && . ./venv/bin/activate && black . && yarn lint
Expand Down Expand Up @@ -128,6 +130,6 @@ preload-map-analysis:
sleep 5
[ -d "./venv" ] && . ./venv/bin/activate &&\
export FLASK_APP=$(CURDIR)/cre.py
python cre.py --preload_map_analysis_target_url 'http://127.0.0.1:5002'
python cre.py --preload_map_analysis_target_url 'http://127.0.0.1:5000'
killall python flask
all: clean lint test dev dev-run
4 changes: 2 additions & 2 deletions Procfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
web: gunicorn cre:app -b 0.0.0.0:5002 --log-file=-g
worker: FLASK_RUN_PORT="5002" FLASK_APP=`pwd`/cre.py python cre.py --start_worker
web: gunicorn cre:app --log-file=-g
worker: FLASK_APP=`pwd`/cre.py python cre.py --start_worker
2 changes: 1 addition & 1 deletion application/frontend/src/hooks/useEnvironment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const prodEnvironment: Environment = {

const devEnvironment: Environment = {
name: 'dev',
apiUrl: 'http://127.0.0.1:5002/rest/v1',
apiUrl: 'http://127.0.0.1:5000/rest/v1',
};

export const useEnvironment = (): Environment =>
Expand Down
22 changes: 11 additions & 11 deletions application/frontend/src/test/basic-e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ describe('App.js', () => {
jest.setTimeout(1000000);
browser = await puppeteer.launch(debug);
page = await browser.newPage();
page.setDefaultTimeout(15001);
page.setDefaultTimeout(15000);
});

it('contains the welcome text', async () => {
await page.goto('http://localhost:5002');
await page.goto('http://localhost:5000');
await page.waitForSelector('#SearchBar');
const text = await page.$eval('#SearchBar', (e) => e.textContent);
expect(text).toContain('Search');
});

it('can search for random strs', async () => {
await page.goto('http://127.0.0.1:5002');
await page.goto('http://127.0.0.1:5000');
await page.waitForSelector('#SearchBar');
await page.type('#SearchBar > div > input', 'asdf');
await page.click('#SearchBar > div > button');
Expand All @@ -35,7 +35,7 @@ describe('App.js', () => {
});

it('can search for cryptography using the free text method and it returns both Nodes and CRES', async () => {
await page.goto('http://127.0.0.1:5002');
await page.goto('http://127.0.0.1:5000');
await page.waitForSelector('#SearchBar');
await page.type('#SearchBar > div > input', 'crypto');
await page.click('#SearchBar > div > button');
Expand All @@ -55,7 +55,7 @@ describe('App.js', () => {
});

it('can search for a standard by name, section and the standard page works as expected', async () => {
await page.goto('http://127.0.0.1:5002/node/standard/ASVS');
await page.goto('http://127.0.0.1:5000/node/standard/ASVS');
await page.waitForSelector('.content');
const text = await page.$$('.content', (e) => e.textContent);
expect(text).not.toContain('No results match your search term');
Expand Down Expand Up @@ -102,7 +102,7 @@ describe('App.js', () => {
});

it('can search for a cre', async () => {
await page.goto('http://127.0.0.1:5002');
await page.goto('http://127.0.0.1:5000');
await page.waitForSelector('#SearchBar');
await page.type('#SearchBar > div > input', '558-807');
await page.click('#SearchBar > div > button');
Expand Down Expand Up @@ -133,7 +133,7 @@ describe('App.js', () => {
});

it('can filter', async () => {
await page.goto('http://127.0.0.1:5002/cre/558-807?applyFilters=true&filters=asvs');
await page.goto('http://127.0.0.1:5000/cre/558-807?applyFilters=true&filters=asvs');
await page.waitForSelector('.cre-page__links-container');
// Get inner text
const innerText = await page.evaluate(
Expand All @@ -144,7 +144,7 @@ describe('App.js', () => {
expect(innerText).not.toContain('NIST');

// ensure case insensitive filtering
await page.goto('http://127.0.0.1:5002/cre/558-807?applyFilters=true&filters=ASVS');
await page.goto('http://127.0.0.1:5000/cre/558-807?applyFilters=true&filters=ASVS');
await page.waitForSelector('.cre-page__links-container');
const intxt = await page.evaluate(
() => (document.querySelector('.cre-page__links-container') as HTMLElement)?.innerText
Expand All @@ -160,10 +160,10 @@ describe('App.js', () => {
});

it('can smartlink', async () => {
const response = await page.goto('http://127.0.0.1:5002/smartlink/standard/CWE/1002');
expect(response.url()).toBe('http://127.0.0.1:5002/node/standard/CWE/sectionid/1002');
const response = await page.goto('http://127.0.0.1:5000/smartlink/standard/CWE/1002');
expect(response.url()).toBe('http://127.0.0.1:5000/node/standard/CWE/sectionid/1002');

const redirectResponse = await page.goto('http://127.0.0.1:5002/smartlink/standard/CWE/404');
const redirectResponse = await page.goto('http://127.0.0.1:5000/smartlink/standard/CWE/404');
expect(redirectResponse.url()).toBe('https://cwe.mitre.org/data/definitions/404.html');
});

Expand Down
2 changes: 1 addition & 1 deletion application/web/web_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -745,4 +745,4 @@ def all_cres() -> Any:


if __name__ == "__main__":
app.run(use_reloader=False, debug=True, port=5002)
app.run(use_reloader=False, debug=True)
Loading