Can login with SSO & change Password

This commit is contained in:
2019-10-09 21:57:56 +02:00
parent 20416ce108
commit a6f25bcbb2
16 changed files with 197 additions and 41 deletions

View File

@@ -1,3 +1,6 @@
import com.sendgrid.helpers.mail.Mail
import com.sendgrid.helpers.mail.objects.Content
import com.sendgrid.helpers.mail.objects.Email
import fr.dcproject.Env
import fr.dcproject.messages.Mailer
import fr.dcproject.module
@@ -17,12 +20,16 @@ class MailerTest: KoinTest, AutoCloseKoinTest() {
@Test
fun `can be send an email`() {
withTestApplication({ module(Env.TEST) }) {
get<Mailer>().sendEmail(
"reset-password@dc-project.fr",
"fabrice.lecomte.be@gmail.com",
"Email Work !",
"Test"
)
get<Mailer>().sendEmail {
Mail(
Email("sso@dc-project.fr"),
"Test",
Email("fabrice.lecomte.be@gmail.com"),
Content("text/plain", "Email Work !")
).apply {
addContent(Content("text/html", "Email <b>Work</b> !"))
}
}
}
}
}

View File

@@ -1,7 +1,6 @@
package feature
import com.auth0.jwt.JWT
import com.auth0.jwt.algorithms.Algorithm
import fr.dcproject.JwtConfig
import fr.dcproject.entity.Citizen
import fr.dcproject.entity.User
@@ -31,7 +30,7 @@ class KtorServerAuthSteps: En, KoinTest {
val citizen = Citizen(
id = UUID.fromString(data["id"]),
name = Citizen.Name(data["firstName"], data["lastName"]),
email = ((data["firstName"] + "-" + data["lastName"]).toLowerCase()) + "@gmail.com",
email = data["email"] ?: ((data["firstName"] + "-" + data["lastName"]).toLowerCase()) + "@dc-project.com",
birthday = DateTime.now(),
user = user
)
@@ -44,7 +43,7 @@ class KtorServerAuthSteps: En, KoinTest {
val jwtAsString: String = JWT.create()
.withIssuer("dc-project.fr")
.withClaim("id", id)
.sign(Algorithm.HMAC512(JwtConfig.secret))
.sign(JwtConfig.algorithm)
val user = User(
id = UUID.fromString(id),
@@ -54,7 +53,7 @@ class KtorServerAuthSteps: En, KoinTest {
val citizen = Citizen(
id = UUID.fromString(id),
name = Citizen.Name(firstName, lastName),
email = ("$firstName-$lastName".toLowerCase())+"@gmail.com",
email = ("$firstName-$lastName".toLowerCase())+"@dc-project.fr",
birthday = DateTime.now(),
user = user
)

View File

@@ -18,3 +18,28 @@ Feature: citizens routes
Then the response status code should be 200
And the response should contain object:
| id | 64b7b379-2298-43ec-b428-ba134930cabd |
Scenario: Can be connect with SSO
Given I have citizen:
| id | c606110c-ff0e-4d09-a79e-74632d7bf7bd |
| firstName | John |
| lastName | Doe |
| email | fabrice.lecomte.be@gmail.com |
When I send a POST request to "/sso" with body:
"""
{
"url": "https://dc-project.fr/password/reset",
"email": "fabrice.lecomte.be@gmail.com"
}
"""
Then the response status code should be 204
Scenario: Can be change my password
Given I am authenticated as Joe Patate with id "c211dca6-aa21-45c2-95ba-c7f2179ee37e"
When I send a PUT request to "/citizens/c211dca6-aa21-45c2-95ba-c7f2179ee37e/password/change" with body:
"""
{
"password": "qwerty"
}
"""
Then the response status code should be 201