Skip to content

Commit

Permalink
🍱(dimail) embark dimail-api as container
Browse files Browse the repository at this point in the history
Embark a dimail-api container, automatically fetched from
their repository, to ensure our "bridge" to dimail-api
is up-to-date when developing.
  • Loading branch information
mjeammet committed Sep 17, 2024
1 parent cc86a3b commit 6d258f8
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ and this project adheres to

## [Unreleased]

### Added

- 🍱 embark dimail-api as container by @mjeammet #366

## [1.1.0] - 2024-09-10

### Added
Expand Down
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ bootstrap: \
back-i18n-compile \
mails-install \
mails-build \
setup-dimail-db \
install-front-desk
.PHONY: bootstrap

Expand All @@ -109,6 +110,7 @@ run: ## start the wsgi (production) and development server
@$(COMPOSE) up --force-recreate -d app-dev
@$(COMPOSE) up --force-recreate -d celery-dev
@$(COMPOSE) up --force-recreate -d keycloak
@$(COMPOSE) up --force-recreate -d dimail
@echo "Wait for postgresql to be up..."
@$(WAIT_KC_DB)
@$(WAIT_DB)
Expand Down
8 changes: 8 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,11 @@ services:
- "8080:8080"
depends_on:
- kc_postgresql

dimail:
image: registry.mim-libre.fr/dimail/dimail-api:latest
environment:
DIMAIL_MODE: FAKE
DIMAIL_JWT_SECRET: fake_jwt_secret
ports:
- "8001:8000"
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,8 @@ def test_api_mailboxes__create_administrator_missing_fields():
assert response.json() == {"secondary_email": ["This field is required."]}


### SYNC TO PROVISIONING API
### REACTING TO DIMAIL-API
### We mock dimail's responses to avoid testing dimail's container too


def test_api_mailboxes__unrelated_user_provisioning_api_not_called():
Expand Down Expand Up @@ -297,7 +298,7 @@ def test_api_mailboxes__domain_owner_or_admin_successful_creation_and_provisioni
"""
Domain owner/admin should be able to create mailboxes.
Provisioning API should be called when owner/admin makes a call.
Expected response contains new email and password.
Succesfull 201 response from dimail should trigger mailbox creation on our side.
"""
# creating all needed objects
access = factories.MailDomainAccessFactory(role=role)
Expand Down Expand Up @@ -367,7 +368,7 @@ def test_api_mailboxes__domain_owner_or_admin_successful_creation_and_provisioni
def test_api_mailboxes__dimail_token_permission_denied():
"""
API should raise a clear "permission denied" error
when receiving a 403_forbidden from dimail.
when receiving a permission denied from dimail upon requesting token.
"""
# creating all needed objects
access = factories.MailDomainAccessFactory(role=enums.MailDomainRoleChoices.OWNER)
Expand Down Expand Up @@ -448,7 +449,7 @@ def test_api_mailboxes__user_unrelated_to_domain():

def test_api_mailboxes__handling_dimail_unexpected_error():
"""
API should raise a clear error when dimail gives an unexpected response.
API should raise a clear error when dimail returns an unexpected response.
"""
# creating all needed objects
access = factories.MailDomainAccessFactory(role=enums.MailDomainRoleChoices.OWNER)
Expand Down
4 changes: 2 additions & 2 deletions src/backend/mailbox_manager/tests/test_models_mailboxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ def test_models_mailboxes__cannot_be_created_for_pending_maildomain():
factories.MailboxFactory(domain=factories.MailDomainFactory())


### SYNC TO DIMAIL-API
### REACTING TO DIMAIL-API
### We mock dimail's responses to avoid testing dimail's container too


@override_settings(MAIL_PROVISIONING_API_CREDENTIALS=None)
Expand Down Expand Up @@ -232,7 +233,6 @@ def test_models_mailboxes__create_mailbox_success(mock_info, mock_error):

# Check headers
headers = rsps.calls[1].request.headers
# assert "Authorization" not in headers
assert headers["Content-Type"] == "application/json"

# Payload sent to mailbox provider
Expand Down
3 changes: 2 additions & 1 deletion src/backend/people/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ class Base(Configuration):

# MAILBOX-PROVISIONING API
MAIL_PROVISIONING_API_URL = values.Value(
default="https://api.dev.ox.numerique.gouv.fr",
default="http://host.docker.internal:8001",
environ_name="MAIL_PROVISIONING_API_URL",
environ_prefix=None,
)
Expand Down Expand Up @@ -580,6 +580,7 @@ class Test(Base):

CELERY_TASK_ALWAYS_EAGER = values.BooleanValue(True)

MAIL_PROVISIONING_API_URL = "http://host.docker.internal:8001"
# this is a dev credentials for mail provisioning API
MAIL_PROVISIONING_API_CREDENTIALS = "bGFfcmVnaWU6cGFzc3dvcmQ="

Expand Down
2 changes: 1 addition & 1 deletion src/helm/env.d/dev/values.desk.yaml.gotmpl
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ backend:
POSTGRES_USER: dinum
POSTGRES_PASSWORD: pass
REDIS_URL: redis://default:pass@redis-master:6379/1
MAIL_PROVISIONING_API_URL: "http://host.docker.internal:8000"
MAIL_PROVISIONING_API_URL: "http://host.docker.internal:8001"
MAIL_PROVISIONING_API_CREDENTIALS:
secretKeyRef:
name: backend
Expand Down

0 comments on commit 6d258f8

Please sign in to comment.