Skip to content
Open
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: 3 additions & 3 deletions JWT/jwt-signature-apis-challenges/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ app.post('/jwt/none', (req, res) => { //None endpoint
const jwt_b64_dec = JWT.decode(jwt_token, { complete: true });
if (jwt_b64_dec.header.alg == 'HS256') {
secret_key = '885ae2060fbedcfb491c5e8aafc92cab5a8057b3d4c39655acce9d4f09280a20';
} else if (jwt_b64_dec.header.alg == 'none') {
secret_key = '';
} else {
res.status(400).json({"error": 'Invalid token'})
}
JWT.verify(jwt_token, secret_key, { algorithms: ['none', 'HS256'], complete: true, audience: 'https://127.0.0.1/jwt/none' }, (err, decoded_token) => {
JWT.verify(jwt_token, secret_key, { algorithms: ['HS256'], complete: true, audience: 'https://127.0.0.1/jwt/none' }, (err, decoded_token) => {
if (err) {
res.status(400).json(err);
} else {
Expand Down
3 changes: 3 additions & 0 deletions Python/Flask_Book_Library/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ ENV PASSWORD=1qaz@WSX
# Instalujemy zależności
RUN pip install --no-cache-dir -r requirements.txt

ENV PYTHONPATH=/app
RUN python -m pytest project/tests --maxfail=1 --disable-warnings -q

# Ustawiamy zmienną środowiskową, aby Flask wiedział, jak uruchomić aplikację
ENV FLASK_APP=app.py
ENV FLASK_RUN_HOST=0.0.0.0
Expand Down
74 changes: 74 additions & 0 deletions Python/Flask_Book_Library/project/tests/test_books.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import pytest
from project.books.models import Book


def test_create_book():
book = Book(
name="Test Book",
author="Tester",
year_published=2020,
book_type="fantasy",
status="available"
)

assert book.name == "Test Book"
assert book.author == "Tester"
assert book.year_published == 2020
assert book.book_type == "fantasy"
assert book.status == "available"


def test_book_repr():
book = Book("A", "B", 1999, "thriller")
rep = repr(book)
assert "Book(" in rep
assert "Name: A" in rep


def test_change_status():
book = Book("Book1", "Author1", 2010, "sci-fi")
# zakładamy, że domyślnie status to "available"
assert book.status == "available"
book.status = "borrowed"
assert book.status == "borrowed"


def test_create_book2():
book = Book("Test Book", "Tester", 2020, "fantasy")
assert book.name == "Test Book"
assert book.author == "Tester"
assert book.year_published == 2020
assert book.book_type == "fantasy"
assert book.status == "available"


def test_change_status2():
book = Book("Book1", "Author1", 2010, "sci-fi")
assert book.status == "available"
book.status = "borrowed"
assert book.status == "borrowed"


def test_book_repr2():
book = Book("A", "B", 1999, "thriller")
rep = repr(book)
assert "Book(" in rep
assert "Name: A" in rep


def test_change_book_type():
book = Book("BookZ", "AuthorZ", 2015, "horror")
assert book.book_type == "horror"
book.book_type = "mystery"
assert book.book_type == "mystery"


def test_default_status():
book = Book("BookDefault", "AuthorDefault", 2021, "science")
assert book.status == "available"


def test_books_equality():
book1 = Book("SameBook", "SameAuthor", 2022, "romance")
book2 = Book("SameBook", "SameAuthor", 2022, "romance")
assert book1 != book2
1 change: 1 addition & 0 deletions Python/Flask_Book_Library/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ SQLAlchemy==2.0.21
typing_extensions==4.8.0
Werkzeug==2.3.7
WTForms==3.0.1
pytest