Skip to content

Commit a11a924

Browse files
committed
Add test for person inbox and outbox
check activitypub content-type Fix create activity response test webfinger Fix review, note voting Add test for person inbox and outbox check activitypub content-type Add importer ( automate creation of Purls and Vulnerabilities by reading the git repo ) Add a small test for the importer Add activitypub tests ( test_person_create_note, test_person_follow_purl , test_person_delete_note , ... ) Add a django post-save signal to clone the git repo when it's created Fix ap_collection error Add auth view , Fix model test Add test for Activity and activity handler Add activitypub basic inbox and outbox Create a way to handel activities Create UserFollowing, PurlFollowers view Remove fixed notes from purl_profile.html Add basic activitypub activity Create notes view , refactor webfinger templates Draft for the new implementation of purl-sync Add a delete follow view ( unsubscribe ) Add basic design activitypub activities Add follow page , FollowView view Fix models test Add review form Create review page Rename notes to comments Fix review-vote, comment-vote Add Create button to repo_list page Remove function from severity_systems.py Add jquery Add basic implementation for vote view Add create comment form , review status form Add review list page , review-list view Add login , logout functionality Add a basic ui for review , review list , create review pages Edit model.py ( use a many-to-many relationship instead of json field ) Add test Add support for webfinger Add pytest run doctests Edit Actor model , Edit create_git_repo and view function Try to make Reputation model more general Add bulma static folders Add create git function Add basic UI, security_team_profile, database_admin_profile Remove the extra relations ( many-to-many ,..) and use JSONField instead Add test for following and follower actors Edit basic django model Add support for pytest, black, isort Add django model test Add missing fields in GitRepo Add basic Implementation for ER diagram Initial config for purl-sync project Signed-off-by: ziadhany <ziadhany2016@gmail.com>
1 parent ea0b934 commit a11a924

81 files changed

Lines changed: 24783 additions & 3 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/main.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ name: run tests
33
on: [push, pull_request]
44

55
env:
6-
DB_NAME: vulnerablecode
7-
DB_USER: vulnerablecode
8-
DB_PASSWORD: vulnerablecode
6+
DB_NAME: purl-sync
7+
DB_USER: purl-sync
8+
DB_PASSWORD: purl-sync
99

1010
jobs:
1111
build:

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,4 @@ Pipfile
103103
*.bak
104104
/.cache/
105105
/tmp/
106+
/purl_sync/venv_purl/

purl_sync/Makefile

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
#
3+
# http://nexb.com and https://github.com/nexB/scancode.io
4+
# The ScanCode.io software is licensed under the Apache License version 2.0.
5+
# Data generated with ScanCode.io is provided as-is without warranties.
6+
# ScanCode is a trademark of nexB Inc.
7+
#
8+
# You may not use this software except in compliance with the License.
9+
# You may obtain a copy of the License at: http://apache.org/licenses/LICENSE-2.0
10+
# Unless required by applicable law or agreed to in writing, software distributed
11+
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12+
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
13+
# specific language governing permissions and limitations under the License.
14+
#
15+
# Data Generated with ScanCode.io is provided on an "AS IS" BASIS, WITHOUT WARRANTIES
16+
# OR CONDITIONS OF ANY KIND, either express or implied. No content created from
17+
# ScanCode.io should be considered or used as legal advice. Consult an Attorney
18+
# for any legal advice.
19+
#
20+
# ScanCode.io is a free software code scanning tool from nexB Inc. and others.
21+
# Visit https://github.com/nexB/scancode.io for support and download.
22+
# Modified for VulnerableCode use
23+
24+
# Python version can be specified with `$ PYTHON_EXE=python3.x make conf`
25+
PYTHON_EXE?=python3
26+
VENV=venv
27+
MANAGE=${VENV}/bin/python manage.py
28+
ACTIVATE?=. ${VENV}/bin/activate;
29+
VIRTUALENV_PYZ=etc/thirdparty/virtualenv.pyz
30+
# Do not depend on Python to generate the SECRET_KEY
31+
GET_SECRET_KEY=`base64 /dev/urandom | head -c50`
32+
# Customize with `$ make envfile ENV_FILE=/etc/vulnerablecode/.env`
33+
ENV_FILE=.env
34+
# Customize with `$ make postgres VULNERABLECODE_DB_PASSWORD=YOUR_PASSWORD`
35+
VULNERABLECODE_DB_PASSWORD=vulnerablecode
36+
37+
virtualenv:
38+
@echo "-> Bootstrap the virtualenv with PYTHON_EXE=${PYTHON_EXE}"
39+
@${PYTHON_EXE} ${VIRTUALENV_PYZ} --never-download --no-periodic-update ${VENV}
40+
41+
conf: virtualenv
42+
@echo "-> Install dependencies"
43+
@${ACTIVATE} pip install -e . -c requirements.txt
44+
45+
dev: virtualenv
46+
@echo "-> Configure and install development dependencies"
47+
@${ACTIVATE} pip install -e .[dev] -c requirements.txt
48+
49+
envfile:
50+
@echo "-> Create the .env file and generate a secret key"
51+
@if test -f ${ENV_FILE}; then echo ".env file exists already"; exit 1; fi
52+
@mkdir -p $(shell dirname ${ENV_FILE}) && touch ${ENV_FILE}
53+
@echo SECRET_KEY=\"${GET_SECRET_KEY}\" > ${ENV_FILE}
54+
55+
isort:
56+
@echo "-> Apply isort changes to ensure proper imports ordering"
57+
${VENV}/bin/isort .
58+
59+
black:
60+
@echo "-> Apply black code formatter"
61+
${VENV}/bin/black .
62+
63+
valid: isort black
64+
65+
check:
66+
@echo "-> Run pycodestyle (PEP8) validation"
67+
@${ACTIVATE} pycodestyle --max-line-length=100 --exclude=venv,lib,thirdparty,docs,migrations,settings.py .
68+
@echo "-> Run isort imports ordering validation"
69+
@${ACTIVATE} isort --check-only .
70+
@echo "-> Run black validation"
71+
@${ACTIVATE} black --check ${BLACK_ARGS}
72+
73+
clean:
74+
@echo "-> Clean the Python env"
75+
rm -rf ${VENV} build/ dist/ vulnerablecode.egg-info/ docs/_build/ pip-selfcheck.json
76+
find . -type f -name '*.py[co]' -delete -o -type d -name __pycache__ -delete
77+
78+
migrate:
79+
@echo "-> Apply database migrations"
80+
${MANAGE} migrate
81+
82+
sqlite:
83+
@echo "-> Configure SQLite database"
84+
@echo VULNERABLECODE_DB_ENGINE=\"django.db.backends.sqlite3\" >> ${ENV_FILE}
85+
@echo VULNERABLECODE_DB_NAME=\"sqlite3.db\" >> ${ENV_FILE}
86+
@$(MAKE) migrate
87+
88+
run:
89+
${MANAGE} runserver 8000 --insecure
90+
91+
test:
92+
@echo "-> Run the test suite"
93+
${ACTIVATE} ${PYTHON_EXE} -m pytest -vvs -m "not webtest"
94+
95+
webtest:
96+
@echo "-> Run web tests"
97+
${ACTIVATE} ${PYTHON_EXE} -m pytest -vvs -m "webtest"

purl_sync/manage.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env python
2+
"""Django's command-line utility for administrative tasks."""
3+
import os
4+
import sys
5+
6+
7+
def main():
8+
"""Run administrative tasks."""
9+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "purl_sync.settings")
10+
try:
11+
from django.core.management import execute_from_command_line
12+
except ImportError as exc:
13+
raise ImportError(
14+
"Couldn't import Django. Are you sure it's installed and "
15+
"available on your PYTHONPATH environment variable? Did you "
16+
"forget to activate a virtual environment?"
17+
) from exc
18+
execute_from_command_line(sys.argv)
19+
20+
21+
if __name__ == "__main__":
22+
main()
455 Bytes
Loading

purl_sync/purl_sync/__init__.py

Whitespace-only changes.

purl_sync/purl_sync/asgi.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
ASGI config for purl_sync project.
3+
4+
It exposes the ASGI callable as a module-level variable named ``application``.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/4.1/howto/deployment/asgi/
8+
"""
9+
10+
import os
11+
12+
from django.core.asgi import get_asgi_application
13+
14+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "purl_sync.settings")
15+
16+
application = get_asgi_application()

purl_sync/purl_sync/settings.py

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
import os
2+
from pathlib import Path
3+
4+
import environ
5+
6+
PROJECT_DIR = Path(__file__).resolve().parent
7+
ROOT_DIR = PROJECT_DIR.parent
8+
# Environment
9+
10+
ENV_FILE = "purl_sync/.env"
11+
if not Path(ENV_FILE).exists():
12+
ENV_FILE = ROOT_DIR / ".env"
13+
14+
env = environ.Env()
15+
environ.Env.read_env(str(ENV_FILE))
16+
17+
DOMAIN = env.str("DOMAIN", "127.0.0.1")
18+
19+
# Build paths inside the project like this: BASE_DIR / 'subdir'.
20+
BASE_DIR = Path(__file__).resolve().parent.parent
21+
22+
# Quick-start development settings - unsuitable for production
23+
# See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/
24+
25+
# SECURITY WARNING: keep the secret key used in production secret!
26+
SECRET_KEY = "django-insecure-uoc-dv7+6%dy7c6(hc$6*z_m-#4y*jp1%-^*5)y&+i9-@j7zup"
27+
28+
# SECURITY WARNING: don't run with debug turned on in production!
29+
DEBUG = True
30+
31+
ALLOWED_HOSTS = []
32+
33+
# Application definition
34+
35+
INSTALLED_APPS = [
36+
"django.contrib.admin",
37+
"django.contrib.auth",
38+
"django.contrib.contenttypes",
39+
"django.contrib.sessions",
40+
"django.contrib.messages",
41+
"django.contrib.staticfiles",
42+
"review",
43+
"oauth2_provider",
44+
]
45+
46+
MIDDLEWARE = [
47+
"django.middleware.security.SecurityMiddleware",
48+
"django.contrib.sessions.middleware.SessionMiddleware",
49+
"django.middleware.common.CommonMiddleware",
50+
"django.middleware.csrf.CsrfViewMiddleware",
51+
"django.contrib.auth.middleware.AuthenticationMiddleware",
52+
"django.contrib.messages.middleware.MessageMiddleware",
53+
"django.middleware.clickjacking.XFrameOptionsMiddleware",
54+
"oauth2_provider.middleware.OAuth2TokenMiddleware",
55+
]
56+
57+
ROOT_URLCONF = "purl_sync.urls"
58+
59+
TEMPLATES = [
60+
{
61+
"BACKEND": "django.template.backends.django.DjangoTemplates",
62+
"DIRS": [],
63+
"APP_DIRS": True,
64+
"OPTIONS": {
65+
"context_processors": [
66+
"django.template.context_processors.debug",
67+
"django.template.context_processors.request",
68+
"django.contrib.auth.context_processors.auth",
69+
"django.contrib.messages.context_processors.messages",
70+
],
71+
},
72+
},
73+
]
74+
75+
WSGI_APPLICATION = "purl_sync.wsgi.application"
76+
77+
# https://docs.djangoproject.com/en/4.1/ref/settings/#databases
78+
# postgresql database
79+
# DATABASES = {
80+
# "default": {
81+
# "ENGINE": env.str("PURL_SYNC_DB_ENGINE", "django.db.backends.postgresql"),
82+
# "HOST": env.str("PURL_SYNC_DB_HOST", "localhost"),
83+
# "NAME": env.str("PURL_SYNC_DB_NAME", "purl-sync"),
84+
# "USER": env.str("PURL_SYNC_DB_USER", "vulnerablecode"),
85+
# "PASSWORD": env.str("PURL_SYNC_DB_PASSWORD", "vulnerablecode"),
86+
# "PORT": env.str("PURL_SYNC_DB_PORT", "5432"),
87+
# }
88+
# }
89+
90+
# sqlite3 database :
91+
DATABASES = {
92+
"default": {
93+
"ENGINE": "django.db.backends.sqlite3",
94+
"NAME": "mydatabase.db",
95+
}
96+
}
97+
98+
# Password validation
99+
# https://docs.djangoproject.com/en/4.1/ref/settings/#auth-password-validators
100+
101+
AUTH_PASSWORD_VALIDATORS = [
102+
{
103+
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
104+
},
105+
{
106+
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
107+
},
108+
{
109+
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
110+
},
111+
{
112+
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
113+
},
114+
]
115+
116+
REST_FRAMEWORK = {
117+
"DEFAULT_AUTHENTICATION_CLASSES": (
118+
"oauth2_provider.contrib.rest_framework.OAuth2Authentication",
119+
"rest_framework.authentication.SessionAuthentication",
120+
),
121+
"DEFAULT_PERMISSION_CLASSES": ("rest_framework.permissions.IsAuthenticated",),
122+
}
123+
124+
OAUTH2_PROVIDER = {
125+
"ACCESS_TOKEN_EXPIRE_SECONDS": 3600,
126+
"REFRESH_TOKEN_EXPIRE_SECONDS": 3600 * 24 * 365,
127+
"SCOPES": {"read": "Read scope", "write": "Write scope"},
128+
}
129+
130+
AUTHENTICATION_BACKENDS = (
131+
"django.contrib.auth.backends.ModelBackend",
132+
"oauth2_provider.backends.OAuth2Backend",
133+
)
134+
# Internationalization
135+
# https://docs.djangoproject.com/en/4.1/topics/i18n/
136+
137+
LANGUAGE_CODE = "en-us"
138+
139+
TIME_ZONE = "UTC"
140+
141+
USE_I18N = True
142+
143+
USE_TZ = True
144+
145+
# Static files (CSS, JavaScript, Images)
146+
# https://docs.djangoproject.com/en/4.1/howto/static-files/
147+
148+
STATIC_URL = "static/"
149+
150+
# Default primary key field type
151+
# https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field
152+
153+
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
154+
155+
MEDIA_URL = "/media/"
156+
MEDIA_ROOT = os.path.join(BASE_DIR, "media")
157+
GIT_PATH = os.path.join(MEDIA_ROOT, "git")
158+
AP_CONTENT_TYPE = "application/activity+json"

0 commit comments

Comments
 (0)