Skip to content

Commit 6092106

Browse files
authored
Merge pull request #8 from helioauth/feature/add-edit-relying-party-name
feat: add relyingPartyName field to application schemas
2 parents 26431b8 + 8ea1f87 commit 6092106

6 files changed

Lines changed: 38 additions & 12 deletions

File tree

docs/openapi/components/schemas/AddApplicationRequest.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,7 @@ properties:
66
description: Name of the new application.
77
relyingPartyHostname:
88
type: string
9-
description: Hostname of the application, e.g. example.com
9+
description: Hostname of the application, e.g. example.com
10+
relyingPartyName:
11+
type: string
12+
description: Name of the relying party presented to clients.

docs/openapi/components/schemas/Application.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ properties:
77
description: Unique identifier for the application.
88
name:
99
type: string
10-
description: Name of the application.
10+
description: Name of the application. Used internally.
1111
createdAt:
1212
type: string
1313
format: date-time
@@ -19,3 +19,6 @@ properties:
1919
relyingPartyHostname:
2020
type: string
2121
description: Hostname of the relying party.
22+
relyingPartyName:
23+
type: string
24+
description: Name of the relying party presented to clients.

docs/openapi/components/schemas/EditApplicationRequest.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,7 @@ properties:
66
description: Name of the application.
77
relyingPartyHostname:
88
type: string
9-
description: Hostname of the relying party.
9+
description: Hostname of the relying party.
10+
relyingPartyName:
11+
type: string
12+
description: Name of the relying party presented to clients.

src/main/java/com/helioauth/passkeys/api/mapper/ClientApplicationMapper.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@
1717
package com.helioauth.passkeys.api.mapper;
1818

1919
import com.helioauth.passkeys.api.domain.ClientApplication;
20+
import com.helioauth.passkeys.api.generated.models.AddApplicationRequest;
2021
import com.helioauth.passkeys.api.generated.models.Application;
2122
import com.helioauth.passkeys.api.generated.models.ApplicationApiKey;
2223
import com.helioauth.passkeys.api.generated.models.EditApplicationRequest;
2324
import org.mapstruct.Mapper;
25+
import org.mapstruct.Mapping;
2426
import org.mapstruct.MappingConstants;
2527
import org.mapstruct.MappingTarget;
2628

@@ -32,9 +34,14 @@
3234
@Mapper(componentModel = MappingConstants.ComponentModel.SPRING)
3335
public interface ClientApplicationMapper {
3436
Application toResponse(ClientApplication clientApplication);
37+
3538
List<Application> toResponse(List<ClientApplication> clientApplication);
3639

3740
ApplicationApiKey toApiKeyResponse(ClientApplication clientApplication);
3841

42+
@Mapping(target = "id", ignore = true) // ID will be generated by the database
43+
@Mapping(target = "apiKey", ignore = true) // API key is generated in the service
44+
ClientApplication toClientApplication(AddApplicationRequest request);
45+
3946
void updateClientApplication(@MappingTarget ClientApplication clientApplication, EditApplicationRequest request);
4047
}

src/main/java/com/helioauth/passkeys/api/service/ClientApplicationService.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import com.helioauth.passkeys.api.generated.models.EditApplicationRequest;
2525
import com.helioauth.passkeys.api.mapper.ClientApplicationMapper;
2626
import lombok.RequiredArgsConstructor;
27+
import lombok.val;
2728
import org.springframework.stereotype.Service;
2829
import org.springframework.transaction.annotation.Transactional;
2930

@@ -62,14 +63,11 @@ public List<Application> listAll() {
6263
}
6364

6465
public Application add(AddApplicationRequest request) {
66+
val clientApplication = clientApplicationMapper.toClientApplication(request);
67+
clientApplication.setApiKey(generateApiKey());
68+
6569
return clientApplicationMapper.toResponse(
66-
repository.save(
67-
ClientApplication.builder()
68-
.name(request.getName())
69-
.apiKey(generateApiKey())
70-
.relyingPartyHostname(request.getRelyingPartyHostname())
71-
.build()
72-
)
70+
repository.save(clientApplication)
7371
);
7472
}
7573

src/test/java/com/helioauth/passkeys/api/service/ClientApplicationServiceTest.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ public class ClientApplicationServiceTest {
5151
public static final Application DTO = new Application()
5252
.id(UUID.randomUUID())
5353
.name("App Name")
54+
.relyingPartyHostname("example.com")
55+
.relyingPartyName("Example App")
5456
.createdAt(Instant.now())
5557
.updatedAt(Instant.now());
5658

@@ -79,6 +81,8 @@ public void addClientApplicationTest() {
7981
// Execute
8082
AddApplicationRequest addApplicationRequest = new AddApplicationRequest();
8183
addApplicationRequest.setName(DTO.getName());
84+
addApplicationRequest.setRelyingPartyHostname(DTO.getRelyingPartyHostname());
85+
addApplicationRequest.setRelyingPartyName(DTO.getRelyingPartyName());
8286
Application result = service.add(addApplicationRequest);
8387

8488
// Capture the argument
@@ -89,6 +93,8 @@ public void addClientApplicationTest() {
8993
assertFalse(savedClientApplication.getApiKey().isEmpty());
9094
assertEquals(DTO.getName(), savedClientApplication.getName());
9195
assertEquals(DTO.getName(), result.getName());
96+
assertEquals(DTO.getRelyingPartyHostname(), savedClientApplication.getRelyingPartyHostname());
97+
assertEquals(DTO.getRelyingPartyName(), savedClientApplication.getRelyingPartyName());
9298
}
9399

94100
@Test
@@ -103,8 +109,8 @@ public void listAllClientApplicationsTest() {
103109
// Validate
104110
assertNotNull(result);
105111
assertEquals(1, result.size());
106-
assertEquals(DTO.getId(), result.get(0).getId());
107-
assertEquals(DTO.getName(), result.get(0).getName());
112+
assertEquals(DTO.getId(), result.getFirst().getId());
113+
assertEquals(DTO.getName(), result.getFirst().getName());
108114
}
109115

110116
@Test
@@ -115,6 +121,8 @@ public void editClientApplicationTest() {
115121
ClientApplication existingClientApplication = ClientApplication.builder()
116122
.id(id)
117123
.name("Old Name")
124+
.relyingPartyHostname("example.com")
125+
.relyingPartyName("Example RP")
118126
.createdAt(Instant.now())
119127
.updatedAt(Instant.now())
120128
.build();
@@ -125,11 +133,15 @@ public void editClientApplicationTest() {
125133
// Execute
126134
EditApplicationRequest editApplicationRequest = new EditApplicationRequest();
127135
editApplicationRequest.setName(newName);
136+
editApplicationRequest.setRelyingPartyHostname("example2.com");
137+
editApplicationRequest.setRelyingPartyName("Example RP 2");
128138
Optional<Application> result = service.edit(id, editApplicationRequest);
129139

130140
// Validate
131141
assertTrue(result.isPresent());
132142
assertEquals(newName, result.get().getName());
143+
assertEquals(editApplicationRequest.getRelyingPartyHostname(), result.get().getRelyingPartyHostname());
144+
assertEquals(editApplicationRequest.getRelyingPartyName(), result.get().getRelyingPartyName());
133145
}
134146

135147
@Test

0 commit comments

Comments
 (0)