Skip to content

Commit

Permalink
Initialize OWASP chapter schema
Browse files Browse the repository at this point in the history
  • Loading branch information
arkid15r committed Feb 4, 2025
1 parent 5402b77 commit 2cdb03a
Show file tree
Hide file tree
Showing 17 changed files with 365 additions and 1 deletion.
2 changes: 1 addition & 1 deletion schema/Dockerfile.test
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ USER owasp
COPY poetry.lock pyproject.toml ./
RUN poetry install --no-root

COPY project.json project.json
COPY *.json ./
COPY tests tests
COPY utils utils
140 changes: 140 additions & 0 deletions schema/chapter.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://raw.githubusercontent.com/OWASP/Nest/main/schema/chapter.json",
"$defs": {
"leader": {
"type": "object",
"title": "Leader",
"description": "A chapter leader.",
"required": ["github"],
"properties": {
"email": {
"description": "The leader's email address.",
"format": "email",
"type": ["string", "null"]
},
"github": {
"type": "string",
"description": "The GitHub username.",
"pattern": "^[a-zA-Z0-9-]{1,39}$"
},
"name": {
"type": ["string", "null"],
"description": "Leader's name."
},
"slack": {
"type": ["string", "null"],
"description": "The Slack username.",
"pattern": "^[a-zA-Z0-9._-]{1,21}$"
}
},
"additionalProperties": false
},
"sponsor": {
"type": "object",
"title": "Sponsor",
"description": "A chapter sponsor.",
"required": [
"name",
"url"
],
"properties": {
"description": {
"type": "string",
"description": "A brief description of the sponsor."
},
"logo": {
"type": "string",
"description": "The URL of the sponsor's logo.",
"format": "uri"
},
"name": {
"type": "string",
"description": "The name of the sponsor or organization."
},
"url": {
"type": "string",
"description": "The URL of the sponsor.",
"format": "uri"
}
},
"additionalProperties": false
}
},

"additionalProperties": false,
"description": "OWASP chapter schema.",
"properties": {
"blog": {
"description": "Chapter's blog.",
"format": "uri",
"type": ["string"]
},
"country": {
"description": "Country.",
"type": "string"
},
"events": {
"description": "Event URLs related to the chapter.",
"type": "array",
"items": {
"format": "uri",
"type": "string"
},
"minItems": 1,
"uniqueItems": true
},
"leaders": {
"description": "Leaders of the chapter.",
"type": "array",
"items": {
"$ref": "#/$defs/leader"
},
"minItems": 2,
"uniqueItems": true
},
"meetup-group": {
"description": "Meetup group.",
"type": "string"
},
"name": {
"description": "The unique name of the chapter.",
"minLength": 10,
"type": "string"
},
"region": {
"description": "Region.",
"type": "string"
},
"sponsors": {
"description": "Sponsors of the chapter.",
"type": "array",
"items": {
"$ref": "#/$defs/sponsor"
},
"minItems": 1
},
"tags": {
"description": "Tags for the chapter",
"type": "array",
"items": {
"type": "string"
},
"minItems": 3,
"uniqueItems": true
},
"website": {
"description": "The official website of the chapter.",
"type": "string",
"format": "url"
}
},
"required": [
"country",
"leaders",
"name",
"tags"
],
"title": "OWASP Chapter",
"type": "object"
}
57 changes: 57 additions & 0 deletions schema/tests/chapter_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
from pathlib import Path

import pytest
import yaml
from utils.validators import validate_data

from tests.conftest import tests_data_dir


def test_positive(chapter_schema):
for file_path in Path(tests_data_dir / "chapter/positive").rglob("*.yaml"):
assert (
validate_data(
chapter_schema,
yaml.safe_load(
file_path.read_text(),
),
)
is None
)


@pytest.mark.parametrize(
("file_path", "error_message"),
[
("blog-none.yaml", "None is not of type 'string'"),
("events-empty.yaml", "[] should be non-empty"),
(
"events-non-unique-urls.yaml",
"['https://example.com/event1', 'https://example.com/event1'] has non-unique elements",
),
(
"leader-email-empty.yaml",
"[{'email': '', 'github': 'leader-1-github', 'name': 'Leader 1 Name'}] is too short",
),
(
"leader-email-missing.yaml",
"[{'email': None, 'github': 'leader-1-github', 'name': 'Leader 1 Name'}] is too short",
),
("name-empty.yaml", "'' is too short"),
("name-none.yaml", "None is not of type 'string'"),
("sponsors-empty-list.yaml", "[] should be non-empty"),
("sponsors-name-missing.yaml", "'name' is a required property"),
("sponsors-url-missing.yaml", "'url' is a required property"),
("website-none.yaml", "None is not of type 'string'"),
],
)
def test_negative(chapter_schema, file_path, error_message):
assert (
validate_data(
chapter_schema,
yaml.safe_load(
Path(tests_data_dir / "chapter/negative" / file_path).read_text(),
),
)
== error_message
)
6 changes: 6 additions & 0 deletions schema/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
schema_dir = tests_dir.parent


@pytest.fixture
def chapter_schema():
with Path(schema_dir / "chapter.json").open() as file:
yield json.load(file)


@pytest.fixture
def project_schema():
with Path(schema_dir / "project.json").open() as file:
Expand Down
12 changes: 12 additions & 0 deletions schema/tests/data/chapter/negative/blog-none.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
blog:
country: India
leaders:
- github: leader-1-github
name: Leader 1 Name
- github: leader-2-github
name: Leader 2 Name
name: OWASP Chapter
tags:
- example-tag-1
- example-tag-2
- example-tag-3
13 changes: 13 additions & 0 deletions schema/tests/data/chapter/negative/events-empty.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
country: India
leaders:
- github: leader-1-github
name: Leader 1 Name
- github: leader-2-github
name: Leader 2 Name
slack: leader-2-slack
name: OWASP Chapter
tags:
- example-tag-1
- example-tag-2
- example-tag-3
events: []
15 changes: 15 additions & 0 deletions schema/tests/data/chapter/negative/events-non-unique-urls.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
country: India
leaders:
- github: leader-1-github
name: Leader 1 Name
- github: leader-2-github
name: Leader 2 Name
slack: leader-2-slack
name: OWASP Chapter
tags:
- example-tag-1
- example-tag-2
- example-tag-3
events:
- https://example.com/event1
- https://example.com/event1
10 changes: 10 additions & 0 deletions schema/tests/data/chapter/negative/leader-email-empty.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
country: India
leaders:
- email: ''
github: leader-1-github
name: Leader 1 Name
name: OWASP Chapter
tags:
- example-tag-1
- example-tag-2
- example-tag-3
10 changes: 10 additions & 0 deletions schema/tests/data/chapter/negative/leader-email-missing.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
country: India
leaders:
- email:
github: leader-1-github
name: Leader 1 Name
name: OWASP Chapter
tags:
- example-tag-1
- example-tag-2
- example-tag-3
11 changes: 11 additions & 0 deletions schema/tests/data/chapter/negative/name-empty.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
country: India
leaders:
- github: leader-name-1
name: Leader Name 1
- github: leader-name-2
name: Leader Name 2
name: ''
tags:
- example-tag-1
- example-tag-2
- example-tag-3
11 changes: 11 additions & 0 deletions schema/tests/data/chapter/negative/name-none.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
country: India
leaders:
- github: leader-name-1
name: Leader Name 1
- github: leader-name-2
name: Leader Name 2
name:
tags:
- example-tag-1
- example-tag-2
- example-tag-3
12 changes: 12 additions & 0 deletions schema/tests/data/chapter/negative/sponsors-empty-list.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
country: India
leaders:
- github: leader-1-github
name: Leader 1 Name
- github: leader-2-github
name: Leader 2 Name
name: OWASP Chapter
tags:
- example-tag-1
- example-tag-2
- example-tag-3
sponsors: []
15 changes: 15 additions & 0 deletions schema/tests/data/chapter/negative/sponsors-name-missing.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
country: India
leaders:
- github: leader-name-1
name: Leader Name 1
- github: leader-name-2
name: Leader Name 2
name: OWASP Chapter
tags:
- example-tag-1
- example-tag-2
- example-tag-3
sponsors:
- description: A great sponsor
logo: https://sponsor1.com/logo.png
url: https://sponsor1.com
15 changes: 15 additions & 0 deletions schema/tests/data/chapter/negative/sponsors-url-missing.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
country: India
leaders:
- github: leader-1-github
name: Leader 1 Name
- github: leader-2-github
name: Leader 2 Name
name: OWASP Chapter
tags:
- example-tag-1
- example-tag-2
- example-tag-3
sponsors:
- description: A great sponsor
logo: https://sponsor1.com/logo.png
name: Sponsor 1
8 changes: 8 additions & 0 deletions schema/tests/data/chapter/negative/website-none.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
country: India
leaders:
- github: leader-1-github
name: Leader 1 Name
name: OWASP Chapter
tags:
- example-tag-1
website:
17 changes: 17 additions & 0 deletions schema/tests/data/chapter/positive/optional-properties.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
blog: https://blog.chapter.com
country: India
events:
- https://example.com/event1
- https://example.com/event2
leaders:
- github: leader-1-github
name: Leader 1 Name
- github: leader-2-github
name: Leader 2 Name
slack: leader-2-slack
name: OWASP Chapter
tags:
- example-tag-1
- example-tag-2
- example-tag-3
website: https://chapter-website.com
12 changes: 12 additions & 0 deletions schema/tests/data/chapter/positive/required-properties.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
country: India
leaders:
- github: leader-1-github
name: Leader 1 Name
- github: leader-2-github
name: Leader 2 Name
slack: leader-2-slack
name: OWASP Chapter
tags:
- chapter-tag-1
- chapter-tag-2
- chapter-tag-3

0 comments on commit 2cdb03a

Please sign in to comment.