Skip to content

Commit

Permalink
backend runs on 5001 (#495)
Browse files Browse the repository at this point in the history
* backend runs on 5002

* switch port to 5k2 as most docker registries and apple airplay run on 5k

* switch port to 5k2 as most docker registries and apple airplay run on 5k

* switch port to 5k2 as most docker registries and apple airplay run on 5k

* switch port to 5k2 as most docker registries and apple airplay run on 5k

---------

Signed-off-by: Spyros <[email protected]>
  • Loading branch information
northdpole committed Jun 9, 2024
1 parent 93f54ae commit 08c7feb
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 32 deletions.
6 changes: 1 addition & 5 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ jobs:
- name: Run app and e2e tests
run: |
yarn build
[ -d "./venv" ] && . ./venv/bin/activate
export FLASK_APP=./cre.py
export FLASK_CONFIG=development
export INSECURE_REQUESTS=1
FLASK_CONFIG=development flask run &
make dev-flask&
sleep 20s
yarn test:e2e
4 changes: 1 addition & 3 deletions Dockerfile-dev
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ FROM python:3.11.0 as run
COPY --from=build /code /code
WORKDIR /code
RUN apt update &&\
apt install -y python3-numpy &&\
pip install virtualenv &&\
make install-deps-python &&\
apt install -y python3-numpy python3-virtualenv python3-pip &&\
make install-python

ENTRYPOINT make dev-flask
18 changes: 8 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,16 @@ 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 && INSECURE_REQUESTS=1 FLASK_APP=`pwd`/cre.py FLASK_CONFIG=development flask run
. ./venv/bin/activate &&\
FLASK_RUN_PORT="5002" INSECURE_REQUESTS=1 FLASK_APP=`pwd`/cre.py FLASK_CONFIG=development flask run

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

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

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

lint:
[ -d "./venv" ] && . ./venv/bin/activate && black . && yarn lint
Expand Down Expand Up @@ -144,6 +142,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:5000'
python cre.py --preload_map_analysis_target_url 'http://127.0.0.1:5002'
killall python flask
all: clean lint test dev dev-run
2 changes: 1 addition & 1 deletion Procfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
web: gunicorn cre:app --log-file=-g
worker: FLASK_RUN_PORT="5001" FLASK_APP=`pwd`/cre.py python cre.py --start_worker
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:5001/rest/v1',
apiUrl: 'http://127.0.0.1:5000/rest/v1',
};

export const useEnvironment = (): Environment =>
Expand Down
20 changes: 10 additions & 10 deletions application/frontend/src/test/basic-e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ describe('App.js', () => {
});

it('contains the welcome text', async () => {
await page.goto('http://localhost:5001');
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:5001');
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:5001');
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:5001/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:5001');
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:5001/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:5001/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:5001/smartlink/standard/CWE/1002');
expect(response.url()).toBe('http://127.0.0.1:5001/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:5001/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
10 changes: 8 additions & 2 deletions application/web/web_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from application.utils.spreadsheet import write_csv
import oauthlib
import google.auth.transport.requests
from application.utils.hash import make_array_hash, make_cache_key

from application import tracer

Expand Down Expand Up @@ -268,6 +269,12 @@ def map_analysis_weak_links() -> Any:
if gap_analysis_dict.get("result"):
return jsonify({"result": gap_analysis_dict.get("result")})

# if conn.exists(cache_key):
# gap_analysis_results = conn.get(cache_key)
# if gap_analysis_results:
# gap_analysis_dict = json.loads(gap_analysis_results)
# if gap_analysis_dict.get("result"):
# return jsonify({"result": gap_analysis_dict.get("result")})
abort(404, "No such Cache")


Expand Down Expand Up @@ -377,7 +384,6 @@ def find_root_cres() -> Any:
opt_format = request.args.get("format")
with CRETracer("get root cres"):
documents = database.get_root_cres()

if documents:
res = [doc.todict() for doc in documents]
result = {"data": res}
Expand Down Expand Up @@ -694,4 +700,4 @@ def all_cres() -> Any:


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

0 comments on commit 08c7feb

Please sign in to comment.