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

Feat/middleware jwt #78

Merged
merged 31 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
316b3a5
feat : add middleware for jwt
AntonioMrtz Oct 2, 2023
690a765
feat : add api_token
AntonioMrtz Oct 2, 2023
e15a73a
test : fix user tests with middleware
AntonioMrtz Oct 2, 2023
21315e5
style : format test_user
AntonioMrtz Oct 2, 2023
b9f7e33
fix : add /docs to bypass_request middleware
AntonioMrtz Oct 2, 2023
a9bf966
test : fix song tests with middleware
AntonioMrtz Oct 2, 2023
f12ef96
feat : remove artist field from create song
AntonioMrtz Oct 2, 2023
7380157
feat : add only user can update his data
AntonioMrtz Oct 2, 2023
5089dae
feat : add token to update song
AntonioMrtz Oct 2, 2023
4e70224
docs : add docs to new missing methods
AntonioMrtz Oct 2, 2023
9ec9d0d
feat : add interceptor with Auth header token jwt
AntonioMrtz Oct 2, 2023
d795d9f
test : fix genre endpoints tests work with middleware
AntonioMrtz Oct 3, 2023
44062c8
feat : add token to create playlist and update playlist
AntonioMrtz Oct 3, 2023
8aea430
test : fix playlist tests with middleware
AntonioMrtz Oct 3, 2023
2c38e4b
style : format modified files
AntonioMrtz Oct 3, 2023
2ee8233
feat : add token to update artist
AntonioMrtz Oct 3, 2023
d33d401
test : fix artist test with middleware
AntonioMrtz Oct 3, 2023
4c82e44
docs : update docs after changes
AntonioMrtz Oct 3, 2023
8d53b44
fix : update frontend with changes to playlist backend
AntonioMrtz Oct 3, 2023
ea89f4f
tests : update dto test with jwt middleware
AntonioMrtz Oct 4, 2023
94843f3
tests : fix all user tests to use middleware
AntonioMrtz Oct 4, 2023
5cfb837
feat : add cookies httponly to frontend
AntonioMrtz Oct 5, 2023
a1e6c17
fix : remove type error while adding credentiales fetch
AntonioMrtz Oct 5, 2023
7ec47f1
fix : remove all Access-Control-Allow-Origin from requests
AntonioMrtz Oct 5, 2023
f4fd70c
feat : add interceptor electron cookie into header Auth
AntonioMrtz Oct 5, 2023
60a5af1
style : fix lint
AntonioMrtz Oct 5, 2023
f17df29
fix : add error check if jwt token dont exist on electron
AntonioMrtz Oct 5, 2023
e62b260
feat : cookie is being set with credentials include in fetch login
AntonioMrtz Oct 5, 2023
130dc49
feat : make middleware enabled again
AntonioMrtz Oct 5, 2023
832b0d0
refactor : add time variable to expire cookie and token
AntonioMrtz Oct 6, 2023
520f607
fix : handle error while failed fetch Playlist
AntonioMrtz Oct 6, 2023
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
12 changes: 6 additions & 6 deletions Backend API/src/__tests__/test_API/api_all_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@
client = TestClient(app)


def patch_history_playback(user_name: str, song_name: str):
def patch_history_playback(user_name: str, song_name: str, headers: dict):
response = client.patch(
f"/usuarios/{user_name}/historial/?nombre_cancion={song_name}")
f"/usuarios/{user_name}/historial/?nombre_cancion={song_name}", headers=headers)
return response


def patch_playlist_saved(user_name: str, playlist_name: str):
def patch_playlist_saved(user_name: str, playlist_name: str, headers: dict):
response = client.patch(
f"/usuarios/{user_name}/playlists_guardadas/?nombre_playlist={playlist_name}")
f"/usuarios/{user_name}/playlists_guardadas/?nombre_playlist={playlist_name}", headers=headers)
return response


def delete_playlist_saved(user_name: str, playlist_name: str):
def delete_playlist_saved(user_name: str, playlist_name: str, headers: dict):
response = client.delete(
f"/usuarios/{user_name}/playlists_guardadas/?nombre_playlist={playlist_name}")
f"/usuarios/{user_name}/playlists_guardadas/?nombre_playlist={playlist_name}", headers=headers)
return response


Expand Down
18 changes: 10 additions & 8 deletions Backend API/src/__tests__/test_API/api_test_artist.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
client = TestClient(app)


def get_artist(name: str):
def get_artist(name: str, headers: dict):

response = client.get(f"/artistas/{name}")
response = client.get(f"/artistas/{name}", headers=headers)
return response


Expand All @@ -21,7 +21,7 @@ def create_artist(name: str, photo: str, password: str):
return response


def update_artist(name: str, photo: str, playlists: list, saved_playlists: list, playback_history: list, uploaded_songs: list):
def update_artist(name: str, photo: str, playlists: list, saved_playlists: list, playback_history: list, uploaded_songs: list, headers: dict):

url = f"/artistas/{name}/?foto={photo}"

Expand All @@ -32,8 +32,10 @@ def update_artist(name: str, photo: str, playlists: list, saved_playlists: list,
"canciones_creadas": uploaded_songs
}

file_type_header = {"Content-Type": "application/json"}

response = client.put(
url, json=payload, headers={"Content-Type": "application/json"}
url, json=payload, headers={**file_type_header, **headers}
)

return response
Expand All @@ -44,11 +46,11 @@ def delete_artist(name: str):
return response


def get_artists():
response = client.get(f"/artistas/")
def get_artists(headers: dict):
response = client.get(f"/artistas/", headers=headers)
return response


def get_play_count_artist(name: str):
response = client.get(f"/artistas/{name}/reproducciones")
def get_play_count_artist(name: str, headers: dict):
response = client.get(f"/artistas/{name}/reproducciones", headers=headers)
return response
8 changes: 4 additions & 4 deletions Backend API/src/__tests__/test_API/api_test_dto.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
client = TestClient(app)


def get_playlist_dto(name: str):
def get_playlist_dto(name: str, headers: dict):

response = client.get(f"/playlists/dto/{name}")
response = client.get(f"/playlists/dto/{name}", headers=headers)
return response


def get_song_dto(name: str):
response = client.get(f"/canciones/dto/{name}")
def get_song_dto(name: str, headers: dict):
response = client.get(f"/canciones/dto/{name}", headers=headers)
return response
28 changes: 17 additions & 11 deletions Backend API/src/__tests__/test_API/api_test_playlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,40 @@
client = TestClient(app)


def create_playlist(name: str, descripcion: str, foto: str, creador: str):
def create_playlist(name: str, descripcion: str, foto: str, headers: dict):

url = f"/playlists/?nombre={name}&foto={foto}&descripcion={descripcion}&creador={creador}"
url = f"/playlists/?nombre={name}&foto={foto}&descripcion={descripcion}"

payload = []

file_type_header = {"Content-Type": "application/json"}

response = client.post(
url, json=payload, headers={"Content-Type": "application/json"}
url, json=payload, headers={**file_type_header, **headers}
)

return response


def get_playlist(name: str):
def get_playlist(name: str, headers: dict):

response = client.get(f"/playlists/{name}")
response = client.get(f"/playlists/{name}", headers=headers)
return response


def get_playlists(song_names: str):
def get_playlists(song_names: str, headers: dict):

response = client.get(f"/playlists/multiple/{song_names}")
response = client.get(f"/playlists/multiple/{song_names}", headers=headers)
return response


def update_playlist(
name: str,
descripcion: str,
foto: str,
nuevo_nombre: str = ""):
headers: dict,
nuevo_nombre: str = ""
):

if nuevo_nombre == "":
url = f"/playlists/{name}/?foto={foto}&descripcion={descripcion}"
Expand All @@ -44,8 +48,10 @@ def update_playlist(

payload = []

file_type_header = {"Content-Type": "application/json"}

response = client.put(
url, json=payload, headers={"Content-Type": "application/json"}
url, json=payload, headers={**file_type_header, **headers}
)

return response
Expand All @@ -56,6 +62,6 @@ def delete_playlist(name: str):
return response


def get_all_playlists():
response = client.get(f"/playlists/")
def get_all_playlists(headers:dict):
response = client.get(f"/playlists/",headers=headers)
return response
24 changes: 12 additions & 12 deletions Backend API/src/__tests__/test_API/api_test_song.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@
def create_song(
name: str,
file_path: str,
artista: str,
genero: str,
foto: str):
foto: str,
headers: dict):

url = f"/canciones/?nombre={name}&artista={artista}&genero={genero}&foto={foto}"
url = f"/canciones/?nombre={name}&genero={genero}&foto={foto}"

with open(file_path, 'rb') as file:
response = client.post(url, files={'file': file})
response = client.post(url, files={'file': file}, headers=headers)
return response


def get_song(name: str):
def get_song(name: str, headers: dict):

response = client.get(f"/canciones/{name}")
response = client.get(f"/canciones/{name}", headers=headers)
return response


Expand All @@ -30,22 +30,22 @@ def delete_song(name: str):
return response


def get_songs():
response = client.get(f"/canciones/")
def get_songs(headers: dict):
response = client.get(f"/canciones/", headers=headers)
return response


def patch_song_number_plays(name: str):
def patch_song_number_plays(name: str, headers: dict):

patch_url = f"/canciones/{name}/numberOfPlays"

response = client.patch(patch_url)
response = client.patch(patch_url, headers=headers)
return response


def get_songs_by_genre(genre : str):
def get_songs_by_genre(genre: str, headers: dict):

get_url = f"/canciones/generos/{genre}"

response = client.get(get_url)
response = client.get(get_url, headers=headers)
return response
10 changes: 6 additions & 4 deletions Backend API/src/__tests__/test_API/api_test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
client = TestClient(app)


def get_user(name: str):
def get_user(name: str, headers: dict):

response = client.get(f"/usuarios/{name}")
response = client.get(f"/usuarios/{name}", headers=headers)
return response


Expand All @@ -21,7 +21,7 @@ def create_user(name: str, photo: str, password: str):
return response


def update_user(name: str, photo: str, playlists: list, saved_playlists: list, playback_history: list):
def update_user(name: str, photo: str, playlists: list, saved_playlists: list, playback_history: list, headers: dict):

url = f"/usuarios/{name}/?foto={photo}"

Expand All @@ -31,8 +31,10 @@ def update_user(name: str, photo: str, playlists: list, saved_playlists: list, p
"playlists_guardadas": saved_playlists
}

file_type_header = {"Content-Type": "application/json"}

response = client.put(
url, json=payload, headers={"Content-Type": "application/json"}
url, json=payload, headers={**file_type_header, **headers}
)

return response
Expand Down
14 changes: 14 additions & 0 deletions Backend API/src/__tests__/test_API/api_token.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from test_API.api_login import post_login
import pytest


def get_user_jwt_header(username : str , password : str):

response = post_login(user_name=username,password=password)
assert response.status_code==200

jwt = response.json()

return {
"authorization": f"{jwt}",
}
Loading