Skip to content

Commit

Permalink
Merge pull request #70 from unb-mds/test/google-oauth2
Browse files Browse the repository at this point in the history
test(users): testes de caso para rota de registro de usuários com oauth2
  • Loading branch information
mateusvrs authored Nov 5, 2023
2 parents a0d063d + c091daa commit f67f114
Show file tree
Hide file tree
Showing 9 changed files with 254 additions and 104 deletions.
185 changes: 93 additions & 92 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ __pycache__
db.sqlite3
media

# Backup files #
*.bak
# Backup files #
*.bak

# If you are using PyCharm #
# If you are using PyCharm #
# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
Expand Down Expand Up @@ -45,93 +45,94 @@ out/
# JIRA plugin
atlassian-ide-plugin.xml

# Python #
*.py[cod]
*$py.class

# Distribution / packaging
.Python build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
.pytest_cache/
nosetests.xml
coverage.xml
*.cover
.hypothesis/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery
celerybeat-schedule.*

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
# Python #
*.py[cod]
*$py.class

# Distribution / packaging
.Python build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
.pytest_cache/
nosetests.xml
coverage.xml
*.cover
.hypothesis/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery
celerybeat-schedule.*

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# mkdocs documentation
/site

# mypy
.mypy_cache/

# Sublime Text #
*.tmlanguage.cache
*.tmPreferences.cache
*.stTheme.cache
*.sublime-workspace
*.sublime-project

# sftp configuration file
sftp-config.json

# Package control specific files Package
Control.last-run
Control.ca-list
Control.ca-bundle
Control.system-ca-bundle
GitHub.sublime-settings

# Visual Studio Code #
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
.history
venv/
ENV/
env.bak/
venv.bak/

# mkdocs documentation
/site

# mypy
.mypy_cache/

# Sublime Text #
*.tmlanguage.cache
*.tmPreferences.cache
*.stTheme.cache
*.sublime-workspace
*.sublime-project

# sftp configuration file
sftp-config.json

# Package control specific files Package
Control.last-run
Control.ca-list
Control.ca-bundle
Control.system-ca-bundle
GitHub.sublime-settings

# Visual Studio Code #
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
.history
.vscode/settings.json
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
all: copy-env setup-env config-mock entrypoint-chmod
copy-env:
cp ./api/.env.example ./api/.env

setup-env:
bash scripts/env.sh

config-mock:
bash scripts/config.sh

entrypoint-chmod:
chmod +x ./api/entrypoint.sh
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ git clone https://github.com/unb-mds/2023-2-Squad11.git

Para rodar o projeto, você precisa instalar as dependências globais, que são:

- GNU Make 4.3 (ou superior)
- Python v3.11.6 e Pip v22.0.2 (ou superior)
- Node v20.9.0 e NPM v10.1.0 (ou superior)
- Docker Engine v24.0.6 e Docker Compose v2.21.0 (ou superior)
Expand All @@ -23,7 +24,7 @@ Para rodar o projeto, você precisa instalar as dependências globais, que são:
Para configurar o ambiente, você pode rodar o seguinte script:

```bash
bash ./scripts/env.sh
make
```

### Dependências do projeto
Expand All @@ -45,9 +46,6 @@ cd web && npm install

# Volte para a raiz do projeto
cd ..

# Confirmar permissão de execução do entrypoint
chmod +x ./api/entrypoint.sh
```

### Execução
Expand Down
3 changes: 3 additions & 0 deletions api/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ POSTGRES_PASSWORD="suagradeunb"
ADMIN_NAME="admin"
ADMIN_PASS="admin"
ADMIN_EMAIL="[email protected]"

# Google OAuth2 Mock
GOOGLE_OAUTH2_MOCK_TOKEN="your_google_oauth2_mock_token"
6 changes: 4 additions & 2 deletions api/core/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,11 @@
}


ACCESS_TOKEN_LIFETIME = timedelta(days=1)
REFRESH_TOKEN_LIFETIME = timedelta(days=30)
SIMPLE_JWT = {
'ACCESS_TOKEN_LIFETIME': timedelta(days=1),
'REFRESH_TOKEN_LIFETIME': timedelta(days=30),
'ACCESS_TOKEN_LIFETIME': ACCESS_TOKEN_LIFETIME,
'REFRESH_TOKEN_LIFETIME': REFRESH_TOKEN_LIFETIME,
'REFRESH_TOKEN_SECURE': True,
'ROTATE_REFRESH_TOKENS': True,
'BLACKLIST_AFTER_ROTATION': True,
Expand Down
11 changes: 10 additions & 1 deletion api/users/backends/google.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import requests
from users.models import User
from decouple import config


class GoogleOAuth2:
Expand All @@ -12,8 +13,16 @@ def get_user_data(cls, access_token: str) -> dict | None:

user_info_url = cls.GOOGLE_OAUTH2_PROVIDER + '/userinfo'
params = {'access_token': access_token}

try:
if access_token == config('GOOGLE_OAUTH2_MOCK_TOKEN'):
mock_user_data = {
'given_name': 'given_name',
'family_name': 'family_name',
'email': '[email protected]'
}
return mock_user_data

response = requests.get(user_info_url, params=params)
if response.status_code == 200:
user_data = response.json()
Expand Down
Loading

0 comments on commit f67f114

Please sign in to comment.