From dcf35eaccd2e51f97a3a32138779c9236c05a4dc Mon Sep 17 00:00:00 2001 From: Fabrice Lecomte Date: Tue, 9 Feb 2021 00:39:26 +0100 Subject: [PATCH] Clean Citizen entities Change plainPassword to just password Add request Input for /login --- src/main/kotlin/component/auth/User.kt | 45 +++++++++---------- .../kotlin/component/auth/UserRepository.kt | 11 +++-- .../kotlin/component/auth/routes/Login.kt | 13 +++++- .../kotlin/component/auth/routes/Register.kt | 11 ++--- src/main/kotlin/component/citizen/Citizen.kt | 13 ++++++ .../component/citizen/CitizenRepository.kt | 4 +- .../citizen/routes/ChangeMyPassword.kt | 9 +++- src/main/resources/openapi.yaml | 2 +- .../functions/user/change_user_password.sql | 2 +- .../sql/functions/user/check_user.sql | 6 +-- .../sql/functions/user/insert_user.sql | 2 +- src/test/kotlin/steps/ArticleSteps.kt | 11 ++--- src/test/kotlin/steps/CitizenSteps.kt | 10 ++--- src/test/kotlin/steps/ConstitutionSteps.kt | 11 ++--- src/test/kotlin/steps/WorkgroupSteps.kt | 14 +++--- src/test/resources/feature/auth.feature | 13 +++--- src/test/resources/feature/citizen.feature | 8 ++-- src/test/sql/citizen.sql | 2 +- src/test/sql/fixtures/1-fixture_user.sql | 6 +-- src/test/sql/opinion.sql | 4 +- src/test/sql/user.sql | 4 +- 21 files changed, 114 insertions(+), 87 deletions(-) diff --git a/src/main/kotlin/component/auth/User.kt b/src/main/kotlin/component/auth/User.kt index 4646198..0fdf6f6 100644 --- a/src/main/kotlin/component/auth/User.kt +++ b/src/main/kotlin/component/auth/User.kt @@ -11,23 +11,34 @@ import io.ktor.auth.Principal import org.joda.time.DateTime import java.util.UUID -class User( +class UserForCreate( id: UUID = UUID.randomUUID(), username: String, + override val password: String, blockedAt: DateTime? = null, - override var plainPassword: String? = null, - override var roles: List = emptyList() -) : UserFull, - UserBasic(id, username, blockedAt), + roles: List = emptyList() +) : User(id, username, blockedAt, roles), + UserWithPasswordI + +open class User( + id: UUID = UUID.randomUUID(), + var username: String, + var blockedAt: DateTime? = null, + var roles: List = emptyList() +) : UserRef(id), EntityCreatedAt by EntityCreatedAtImp(), EntityUpdatedAt by EntityUpdatedAtImp() -@Deprecated("") -open class UserBasic( - id: UUID = UUID.randomUUID(), - override var username: String, - override var blockedAt: DateTime? = null -) : UserBasicI, UserRef(id) +interface UserWithPasswordI { + val id: UUID + val password: String +} + +class UserWithPassword( + id: UUID, + override val password: String, +) : UserWithPasswordI, + UserRef(id) open class UserRef( id: UUID = UUID.randomUUID() @@ -37,18 +48,6 @@ interface UserI : UuidEntityI, Principal { enum class Roles { ROLE_USER, ROLE_ADMIN } } -@Deprecated("") -interface UserBasicI : UserI { - var username: String - var blockedAt: DateTime? -} - -@Deprecated("") -interface UserFull : UserBasicI, EntityCreatedAt, EntityUpdatedAt { - var plainPassword: String? - var roles: List -} - interface UserForAuthI : UserI { var roles: List var blockedAt: DateTime? diff --git a/src/main/kotlin/component/auth/UserRepository.kt b/src/main/kotlin/component/auth/UserRepository.kt index 26ace7d..ed6902b 100644 --- a/src/main/kotlin/component/auth/UserRepository.kt +++ b/src/main/kotlin/component/auth/UserRepository.kt @@ -4,19 +4,18 @@ import fr.postgresjson.connexion.Requester import fr.postgresjson.repository.RepositoryI import io.ktor.auth.UserPasswordCredential import java.util.UUID -import fr.dcproject.component.auth.User as UserEntity class UserRepository(override var requester: Requester) : RepositoryI { - fun findByCredentials(credentials: UserPasswordCredential): UserEntity? { + fun findByCredentials(credentials: UserPasswordCredential): User? { return requester .getFunction("check_user") .selectOne( "username" to credentials.name, - "plain_password" to credentials.password + "password" to credentials.password ) } - fun findById(id: UUID): UserEntity { + fun findById(id: UUID): User { return requester .getFunction("find_user_by_id") .selectOne( @@ -24,13 +23,13 @@ class UserRepository(override var requester: Requester) : RepositoryI { ) ?: throw UserNotFound(id) } - fun insert(user: UserEntity): UserEntity? { + fun insert(user: User): User? { return requester .getFunction("insert_user") .selectOne("resource" to user) } - fun changePassword(user: UserFull) { + fun changePassword(user: UserWithPassword) { requester .getFunction("change_user_password") .sendQuery("resource" to user) diff --git a/src/main/kotlin/component/auth/routes/Login.kt b/src/main/kotlin/component/auth/routes/Login.kt index c7fc25f..e8a9e67 100644 --- a/src/main/kotlin/component/auth/routes/Login.kt +++ b/src/main/kotlin/component/auth/routes/Login.kt @@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.exc.MismatchedInputException import fr.dcproject.common.utils.receiveOrBadRequest import fr.dcproject.component.auth.UserRepository import fr.dcproject.component.auth.jwt.makeToken +import fr.dcproject.component.auth.routes.Login.LoginRequest.Input import io.ktor.application.call import io.ktor.auth.UserPasswordCredential import io.ktor.http.HttpStatusCode @@ -17,12 +18,20 @@ import io.ktor.routing.Route @KtorExperimentalLocationsAPI object Login { @Location("/login") - class LoginRequest + class LoginRequest { + data class Input( + val username: String, + val password: String, + ) + } fun Route.authLogin(userRepo: UserRepository) { post { try { - val credentials = call.receiveOrBadRequest() + val credentials = call.receiveOrBadRequest().run { + UserPasswordCredential(username, password) + } + userRepo.findByCredentials(credentials)?.let { user -> call.respondText(user.makeToken()) } ?: call.respond(HttpStatusCode.BadRequest, "Username not exist or password is wrong") diff --git a/src/main/kotlin/component/auth/routes/Register.kt b/src/main/kotlin/component/auth/routes/Register.kt index 1cdc248..a2b8843 100644 --- a/src/main/kotlin/component/auth/routes/Register.kt +++ b/src/main/kotlin/component/auth/routes/Register.kt @@ -3,10 +3,11 @@ package fr.dcproject.component.auth.routes import com.fasterxml.jackson.module.kotlin.MissingKotlinParameterException import fr.dcproject.common.utils.receiveOrBadRequest import fr.dcproject.component.auth.User +import fr.dcproject.component.auth.UserForCreate import fr.dcproject.component.auth.UserI import fr.dcproject.component.auth.jwt.makeToken import fr.dcproject.component.auth.routes.Register.RegisterRequest.Input -import fr.dcproject.component.citizen.Citizen +import fr.dcproject.component.citizen.CitizenForCreate import fr.dcproject.component.citizen.CitizenI import fr.dcproject.component.citizen.CitizenRepository import io.ktor.application.call @@ -39,21 +40,21 @@ object Register { ) data class User( val username: String, - val plainPassword: String? = null + val password: String ) } } fun Route.authRegister(citizenRepo: CitizenRepository) { - fun Input.toCitizen(): Citizen = Citizen( + fun Input.toCitizen(): CitizenForCreate = CitizenForCreate( name = CitizenI.Name(name.firstName, name.lastName, name.civility), birthday = birthday, email = email, followAnonymous = followAnonymous, voteAnonymous = voteAnonymous, - user = User( + user = UserForCreate( username = user.username, - plainPassword = user.plainPassword, + password = user.password, roles = listOf(UserI.Roles.ROLE_USER) ) ) diff --git a/src/main/kotlin/component/citizen/Citizen.kt b/src/main/kotlin/component/citizen/Citizen.kt index f1a3dc5..a22dca2 100644 --- a/src/main/kotlin/component/citizen/Citizen.kt +++ b/src/main/kotlin/component/citizen/Citizen.kt @@ -1,6 +1,7 @@ package fr.dcproject.component.citizen import fr.dcproject.component.auth.User +import fr.dcproject.component.auth.UserForCreate import fr.dcproject.component.auth.UserI import fr.dcproject.component.auth.UserRef import fr.dcproject.component.citizen.CitizenI.Name @@ -14,6 +15,18 @@ import fr.postgresjson.entity.UuidEntityI import org.joda.time.DateTime import java.util.UUID +class CitizenForCreate( + val name: Name, + val email: String, + val birthday: DateTime, + val voteAnonymous: Boolean = true, + val followAnonymous: Boolean = true, + override val user: UserForCreate, + id: UUID = UUID.randomUUID(), +) : CitizenI, + CitizenRefWithUser(id, user), + EntityCreatedAt by EntityCreatedAtImp() + class Citizen( override val id: UUID = UUID.randomUUID(), override val name: Name, diff --git a/src/main/kotlin/component/citizen/CitizenRepository.kt b/src/main/kotlin/component/citizen/CitizenRepository.kt index 220e2c3..1b9ca97 100644 --- a/src/main/kotlin/component/citizen/CitizenRepository.kt +++ b/src/main/kotlin/component/citizen/CitizenRepository.kt @@ -40,11 +40,11 @@ class CitizenRepository(override var requester: Requester) : RepositoryI { "search" to search ) - fun upsert(citizen: CitizenFull): Citizen? = requester + fun upsert(citizen: Citizen): Citizen? = requester .getFunction("upsert_citizen") .selectOne("resource" to citizen) - fun insertWithUser(citizen: CitizenFull): Citizen? = requester + fun insertWithUser(citizen: CitizenForCreate): Citizen? = requester .getFunction("insert_citizen_with_user") .selectOne("resource" to citizen) } diff --git a/src/main/kotlin/component/citizen/routes/ChangeMyPassword.kt b/src/main/kotlin/component/citizen/routes/ChangeMyPassword.kt index 524bed9..8522c0f 100644 --- a/src/main/kotlin/component/citizen/routes/ChangeMyPassword.kt +++ b/src/main/kotlin/component/citizen/routes/ChangeMyPassword.kt @@ -3,6 +3,7 @@ package fr.dcproject.component.citizen.routes import fr.dcproject.common.security.assert import fr.dcproject.common.utils.receiveOrBadRequest import fr.dcproject.component.auth.UserRepository +import fr.dcproject.component.auth.UserWithPassword import fr.dcproject.component.auth.citizen import fr.dcproject.component.auth.citizenOrNull import fr.dcproject.component.citizen.CitizenAccessControl @@ -31,8 +32,12 @@ object ChangeMyPassword { ac.assert { canChangePassword(it.citizen, citizenOrNull) } val content = call.receiveOrBadRequest() userRepository.findByCredentials(UserPasswordCredential(citizen.user.username, content.oldPassword)) ?: throw BadRequestException("Bad Password") - citizen.user.plainPassword = content.newPassword - userRepository.changePassword(citizen.user) + userRepository.changePassword( + UserWithPassword( + citizen.user.id, + content.newPassword, + ) + ) call.respond(HttpStatusCode.Created) } diff --git a/src/main/resources/openapi.yaml b/src/main/resources/openapi.yaml index 218c577..5a04424 100644 --- a/src/main/resources/openapi.yaml +++ b/src/main/resources/openapi.yaml @@ -1330,7 +1330,7 @@ components: - $ref: '#/components/schemas/UserBase' - type: object properties: - plain_password: + password: type: string required: true example: diff --git a/src/main/resources/sql/functions/user/change_user_password.sql b/src/main/resources/sql/functions/user/change_user_password.sql index e1e8593..8c5b77f 100644 --- a/src/main/resources/sql/functions/user/change_user_password.sql +++ b/src/main/resources/sql/functions/user/change_user_password.sql @@ -2,7 +2,7 @@ create or replace function change_user_password(resource json) returns void lang $$ begin update "user" - set password = crypt(resource->>'plain_password', gen_salt('bf', 8)) + set password = crypt(resource->>'password', gen_salt('bf', 8)) where id = (resource->>'id')::uuid; return; diff --git a/src/main/resources/sql/functions/user/check_user.sql b/src/main/resources/sql/functions/user/check_user.sql index 8cfcec0..c84a49b 100644 --- a/src/main/resources/sql/functions/user/check_user.sql +++ b/src/main/resources/sql/functions/user/check_user.sql @@ -1,7 +1,5 @@ -create or replace function check_user(in username text, in plain_password text, out resource json) language plpgsql as +create or replace function check_user(in _username text, in _password text, out resource json) language plpgsql as $$ -declare - _username alias for username; begin select case when count(u) = 1 @@ -10,7 +8,7 @@ begin into resource from "user" as u where u.username = lower(_username) - and u.password = crypt(plain_password, u.password) + and u.password = crypt(_password, u.password) group by u; end; $$; diff --git a/src/main/resources/sql/functions/user/insert_user.sql b/src/main/resources/sql/functions/user/insert_user.sql index 1b50dd6..bdc8763 100644 --- a/src/main/resources/sql/functions/user/insert_user.sql +++ b/src/main/resources/sql/functions/user/insert_user.sql @@ -7,7 +7,7 @@ begin select coalesce(t.id, uuid_generate_v4()), t.username, - crypt(resource->>'plain_password', gen_salt('bf', 8)), + crypt(resource->>'password', gen_salt('bf', 8)), case when t.blocked_at is not null then now() else null end, t.roles from json_populate_record(null::"user", resource) t diff --git a/src/test/kotlin/steps/ArticleSteps.kt b/src/test/kotlin/steps/ArticleSteps.kt index c79a188..64544a1 100644 --- a/src/test/kotlin/steps/ArticleSteps.kt +++ b/src/test/kotlin/steps/ArticleSteps.kt @@ -4,7 +4,9 @@ import fr.dcproject.common.utils.toUUID import fr.dcproject.component.article.ArticleForUpdate import fr.dcproject.component.article.ArticleForView import fr.dcproject.component.article.ArticleRepository +import fr.dcproject.component.auth.UserForCreate import fr.dcproject.component.citizen.Citizen +import fr.dcproject.component.citizen.CitizenForCreate import fr.dcproject.component.citizen.CitizenI import fr.dcproject.component.citizen.CitizenRepository import fr.dcproject.component.comment.article.CommentArticleRepository @@ -16,7 +18,6 @@ import org.joda.time.DateTime import org.koin.test.KoinTest import org.koin.test.get import java.util.UUID -import fr.dcproject.component.auth.User as UserEntity class ArticleSteps : En, KoinTest { init { @@ -57,16 +58,16 @@ class ArticleSteps : En, KoinTest { } else { val first = "firstName" + UUID.randomUUID().toString() val last = "lastName" + UUID.randomUUID().toString() - Citizen( + CitizenForCreate( birthday = DateTime.now(), name = CitizenI.Name( first, last ), email = "$first@fakeemail.com", - user = UserEntity(username = username, plainPassword = "azerty") - ).also { - get().insertWithUser(it) + user = UserForCreate(username = username, password = "azerty") + ).let { + get().insertWithUser(it) ?: error("Unable to create User") } } diff --git a/src/test/kotlin/steps/CitizenSteps.kt b/src/test/kotlin/steps/CitizenSteps.kt index fdf8540..1d7384e 100644 --- a/src/test/kotlin/steps/CitizenSteps.kt +++ b/src/test/kotlin/steps/CitizenSteps.kt @@ -1,7 +1,7 @@ package steps -import fr.dcproject.component.auth.User -import fr.dcproject.component.citizen.Citizen +import fr.dcproject.component.auth.UserForCreate +import fr.dcproject.component.citizen.CitizenForCreate import fr.dcproject.component.citizen.CitizenI import fr.dcproject.component.citizen.CitizenRepository import io.cucumber.datatable.DataTable @@ -40,12 +40,12 @@ class CitizenSteps : En, KoinTest { val id: UUID = id ?: params?.get("id")?.let { UUID.fromString(it) } ?: UUID.randomUUID() val email = params?.get("email") ?: ("$firstName-$lastName".toLowerCase()) + "@dc-project.fr" - val user = User( + val user = UserForCreate( id = id, username = "$firstName-$lastName".toLowerCase(), - plainPassword = "azerty" + password = "azerty", ) - val citizen = Citizen( + val citizen = CitizenForCreate( id = id, name = CitizenI.Name(firstName, lastName), email = email, diff --git a/src/test/kotlin/steps/ConstitutionSteps.kt b/src/test/kotlin/steps/ConstitutionSteps.kt index acf1fd4..2709b38 100644 --- a/src/test/kotlin/steps/ConstitutionSteps.kt +++ b/src/test/kotlin/steps/ConstitutionSteps.kt @@ -2,7 +2,9 @@ package steps import fr.dcproject.common.utils.toUUID import fr.dcproject.component.article.ArticleRef +import fr.dcproject.component.auth.UserForCreate import fr.dcproject.component.citizen.Citizen +import fr.dcproject.component.citizen.CitizenForCreate import fr.dcproject.component.citizen.CitizenI import fr.dcproject.component.citizen.CitizenRepository import fr.dcproject.component.citizen.CitizenWithUserI @@ -18,7 +20,6 @@ import org.joda.time.DateTime import org.koin.test.KoinTest import org.koin.test.get import java.util.UUID -import fr.dcproject.component.auth.User as UserEntity class ConstitutionSteps : En, KoinTest { init { @@ -55,16 +56,16 @@ class ConstitutionSteps : En, KoinTest { } else { val first = "firstName" + UUID.randomUUID().toString() val last = "lastName" + UUID.randomUUID().toString() - Citizen( + CitizenForCreate( birthday = DateTime.now(), name = CitizenI.Name( first, last ), email = "$first@fakeemail.com", - user = UserEntity(username = username, plainPassword = "azerty") - ).also { - get().insertWithUser(it) + user = UserForCreate(username = username, password = "azerty") + ).let { + get().insertWithUser(it) ?: error("Unable to create User") } } diff --git a/src/test/kotlin/steps/WorkgroupSteps.kt b/src/test/kotlin/steps/WorkgroupSteps.kt index e8a8922..902f3c4 100644 --- a/src/test/kotlin/steps/WorkgroupSteps.kt +++ b/src/test/kotlin/steps/WorkgroupSteps.kt @@ -1,8 +1,8 @@ package steps import fr.dcproject.common.utils.toUUID -import fr.dcproject.component.auth.User -import fr.dcproject.component.citizen.Citizen +import fr.dcproject.component.auth.UserForCreate +import fr.dcproject.component.citizen.CitizenForCreate import fr.dcproject.component.citizen.CitizenI import fr.dcproject.component.citizen.CitizenRef import fr.dcproject.component.citizen.CitizenRepository @@ -39,17 +39,17 @@ class WorkgroupSteps : En, KoinTest { get().findByUsername(it.toLowerCase().replace(' ', '-')) } ?: run { val username = "paul-langevin".toLowerCase() + UUID.randomUUID() - val user = User( + val user = UserForCreate( username = username, - plainPassword = "azerty" + password = "azerty", ) - Citizen( + CitizenForCreate( name = CitizenI.Name("Paul", "Langevin"), email = "$username@dc-project.fr", birthday = DateTime.now(), user = user - ).also { - get().insertWithUser(it) + ).let { + get().insertWithUser(it) ?: error("Unable to create User") } } diff --git a/src/test/resources/feature/auth.feature b/src/test/resources/feature/auth.feature index 9ff7e3e..5974817 100644 --- a/src/test/resources/feature/auth.feature +++ b/src/test/resources/feature/auth.feature @@ -1,7 +1,7 @@ @auth Feature: Auth routes - Scenario: The route for create citizen must response a 200 and return object + Scenario: I can resiter When I send a POST request to "/register" with body: """ { @@ -9,7 +9,7 @@ Feature: Auth routes "birthday": "2001-01-01", "user":{ "username": "george-junior", - "plain_password": "azerty" + "password": "azerty" }, "email": "george-junior@gmail.com" } @@ -20,7 +20,7 @@ Feature: Auth routes eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9. """ - Scenario: The route for create citizen must response a 400 and return object + Scenario: I cannot create user if no username was sent When I send a POST request to "/register" with body: """ { @@ -28,18 +28,19 @@ Feature: Auth routes "birthday": "2001-01-01", "user":{ "username": "", - "plain_password": "" + "password": "" } } """ Then the response status code should be 400 - Scenario: The route for create citizen must response a 200 and return object + Scenario: I can login with username and password + The route for create citizen must response a 200 and return object Given I have citizen Niels Bohr When I send a POST request to "/login" with body: """ { - "name": "niels-bohr", + "username": "niels-bohr", "password": "azerty" } """ diff --git a/src/test/resources/feature/citizen.feature b/src/test/resources/feature/citizen.feature index b75a82c..43c9814 100644 --- a/src/test/resources/feature/citizen.feature +++ b/src/test/resources/feature/citizen.feature @@ -1,13 +1,13 @@ @citizen Feature: citizens routes - Scenario: The route for get citizens must response a 200 + Scenario: I can get Citizens informations Given I have citizen Jean Perrin with ID "5267a5c6-af42-4a02-aa2b-6b71d2e43973" And I am authenticated as Jean Perrin When I send a GET request to "/citizens" Then the response status code should be 200 - Scenario: The route for get one citizen must response a 200 and return citizen + Scenario: I can get specific Citizen informations Given I have citizen Linus Pauling with ID "47a05c0f-7329-46c3-a7d0-325db37e9114" Given I am authenticated as Linus Pauling When I send a GET request to "/citizens/47a05c0f-7329-46c3-a7d0-325db37e9114" @@ -15,7 +15,7 @@ Feature: citizens routes And the response should contain object: | id | 47a05c0f-7329-46c3-a7d0-325db37e9114 | - Scenario: Can get connected citizen + Scenario: I can get my citizen informations when I was connected Given I have citizen Henri Becquerel with ID "47356809-c8ef-4649-8b99-1c5cb9886d38" And I am authenticated as Henri Becquerel When I send a GET request to "/citizens/current" @@ -24,7 +24,7 @@ Feature: citizens routes | id | 47356809-c8ef-4649-8b99-1c5cb9886d38 | @online - Scenario: Can be connect with Passwordless auth + Scenario: I can be connect with Passwordless auth Given I have citizen | id | c606110c-ff0e-4d09-a79e-74632d7bf7bd | | email | fabrice.lecomte.be@gmail.com | diff --git a/src/test/sql/citizen.sql b/src/test/sql/citizen.sql index dc9028c..2738a3e 100644 --- a/src/test/sql/citizen.sql +++ b/src/test/sql/citizen.sql @@ -4,7 +4,7 @@ declare wrong_citizen json; _user_id uuid := fixture_user(); created_citizen json := '{"name": {"first_name":"George", "last_name":"MICHEL"}, "birthday": "2001-01-01", "email":"george.michel@gmail.com"}'; - created_citizen_with_user json := '{"name": {"first_name":"George", "last_name":"MICHEL"}, "birthday": "2001-01-01", "email":"george.michel2@gmail.com", "user":{"username": "george junior", "plain_password": "azerty", "roles": ["ROLE_USER"]}}'; + created_citizen_with_user json := '{"name": {"first_name":"George", "last_name":"MICHEL"}, "birthday": "2001-01-01", "email":"george.michel2@gmail.com", "user":{"username": "george junior", "password": "azerty", "roles": ["ROLE_USER"]}}'; selected_citizen json; begin created_citizen := jsonb_set(created_citizen::jsonb, '{user}'::text[], jsonb_build_object('id', _user_id::text), true)::json; diff --git a/src/test/sql/fixtures/1-fixture_user.sql b/src/test/sql/fixtures/1-fixture_user.sql index e7e61d0..a734d3f 100644 --- a/src/test/sql/fixtures/1-fixture_user.sql +++ b/src/test/sql/fixtures/1-fixture_user.sql @@ -5,11 +5,11 @@ declare created_user json; begin if (name = 'george') then - created_user = '{"username": "george", "plain_password": "azerty", "roles": ["ROLE_USER"]}'; + created_user = '{"username": "george", "password": "azerty", "roles": ["ROLE_USER"]}'; elseif (name = 'john') then - created_user = '{"username": "john", "plain_password": "qwerty", "roles": ["ROLE_USER"]}'; + created_user = '{"username": "john", "password": "qwerty", "roles": ["ROLE_USER"]}'; elseif (name = 'tesla') then - created_user = '{"username": "tesla", "plain_password": "azerty", "roles": ["ROLE_USER"]}'; + created_user = '{"username": "tesla", "password": "azerty", "roles": ["ROLE_USER"]}'; end if; select insert_user(created_user) into created_user; diff --git a/src/test/sql/opinion.sql b/src/test/sql/opinion.sql index 7d82fac..cddaf68 100644 --- a/src/test/sql/opinion.sql +++ b/src/test/sql/opinion.sql @@ -1,8 +1,8 @@ do $$ declare - created_user json := '{"username": "george", "plain_password": "azerty", "roles": ["ROLE_USER"]}'; - created_user2 json := '{"username": "george2", "plain_password": "azerty", "roles": ["ROLE_USER"]}'; + created_user json := '{"username": "george", "password": "azerty", "roles": ["ROLE_USER"]}'; + created_user2 json := '{"username": "george2", "password": "azerty", "roles": ["ROLE_USER"]}'; _citizen_id uuid; _citizen_id2 uuid; created_citizen json := $json$ diff --git a/src/test/sql/user.sql b/src/test/sql/user.sql index da1ff30..39a1162 100644 --- a/src/test/sql/user.sql +++ b/src/test/sql/user.sql @@ -1,7 +1,7 @@ do $$ declare - created_user json := '{"username": "george", "plain_password": "azerty", "roles": ["ROLE_USER"]}'; + created_user json := '{"username": "george", "password": "azerty", "roles": ["ROLE_USER"]}'; user_with_other_password json; selected_user json; exist_user json; @@ -26,7 +26,7 @@ begin assert exist_user->>'password' is null, format('the function check_user must not be return the password, %s is return', exist_user::text); -- test change password - user_with_other_password = jsonb_set(created_user::jsonb, '{plain_password}', '"qwerty"'::jsonb); + user_with_other_password = jsonb_set(created_user::jsonb, '{password}', '"qwerty"'::jsonb); perform change_user_password(user_with_other_password); select check_user('george', 'qwerty') into exist_user; assert exist_user->>'username' = 'george', format('the function change_user_password must change password: %s', exist_user::text);