From b23851abf4ad04825afa685672f766d688f4c8e1 Mon Sep 17 00:00:00 2001 From: Pascal Grimaud Date: Sat, 23 Apr 2022 10:30:26 +0200 Subject: [PATCH] Front: add security jwt basic auth button --- .../springboot/primary/Generator.component.ts | 9 +++ .../app/springboot/primary/Generator.vue | 9 +++ .../cypress/integration/Generator.spec.ts | 1 + .../spec/springboot/primary/Generator.spec.ts | 55 +++++++++++++++++++ 4 files changed, 74 insertions(+) diff --git a/src/main/webapp/app/springboot/primary/Generator.component.ts b/src/main/webapp/app/springboot/primary/Generator.component.ts index 28e6d80d0a7..e551ea843d6 100644 --- a/src/main/webapp/app/springboot/primary/Generator.component.ts +++ b/src/main/webapp/app/springboot/primary/Generator.component.ts @@ -76,6 +76,14 @@ export default defineComponent({ } }; + const addSpringBootSecurityJWTBasicAuth = async (): Promise => { + if (project.value.folder !== '') { + await springBootService + .addBasicAuthJWT(toProject(project.value)) + .catch(error => logger.error('Adding SpringBoot Security JWT Basic Auth to project failed', error)); + } + }; + const addAngular = async (): Promise => { if (project.value.folder !== '') { if (isAngularWithStyle.value) { @@ -151,6 +159,7 @@ export default defineComponent({ addSpringBoot, addSpringBootMvcTomcat, addSpringBootSecurityJWT, + addSpringBootSecurityJWTBasicAuth, addAngular, addReact, addVue, diff --git a/src/main/webapp/app/springboot/primary/Generator.vue b/src/main/webapp/app/springboot/primary/Generator.vue index 49569e95cc8..8e0d4490c17 100644 --- a/src/main/webapp/app/springboot/primary/Generator.vue +++ b/src/main/webapp/app/springboot/primary/Generator.vue @@ -595,6 +595,15 @@ > Security JWT + +
{ cy.get(generatorSelector('add-spring-boot-button')).contains('Spring Boot'); cy.get(generatorSelector('add-spring-boot-mvc-tomcat-button')).contains('Spring MVC Tomcat'); cy.get(generatorSelector('add-spring-boot-jwt-button')).contains('Security JWT'); + cy.get(generatorSelector('add-spring-boot-jwt-basic-auth-button')).contains('Security JWT Basic Auth'); }); it('should display angular', () => { diff --git a/src/test/javascript/spec/springboot/primary/Generator.spec.ts b/src/test/javascript/spec/springboot/primary/Generator.spec.ts index d57e1c6c71b..428f115dd48 100644 --- a/src/test/javascript/spec/springboot/primary/Generator.spec.ts +++ b/src/test/javascript/spec/springboot/primary/Generator.spec.ts @@ -400,6 +400,61 @@ describe('Generator', () => { expect(message).toBe('Adding SpringBoot Security JWT to project failed'); }); + it('should not add SpringBoot Security JWT Basic Auth when project path is not filled', async () => { + const springBootService = stubSpringBootService(); + springBootService.addBasicAuthJWT.resolves({}); + await wrap({ springBootService }); + await selectSection('springboot'); + + const button = wrapper.find('#springboot-jwt-basic-auth'); + await button.trigger('click'); + + expect(springBootService.addBasicAuthJWT.called).toBe(false); + }); + + it('should add SpringBoot Security JWT Basic Auth when project path is filled', async () => { + const springBootService = stubSpringBootService(); + springBootService.addBasicAuthJWT.resolves({}); + await wrap({ springBootService }); + const projectToUpdate: ProjectToUpdate = createProjectToUpdate({ + folder: 'project/path', + baseName: 'beer', + projectName: 'Beer Project', + packageName: 'tech.jhipster.beer', + serverPort: '8080', + }); + await fillFullForm(projectToUpdate); + await selectSection('springboot'); + + const button = wrapper.find('#springboot-jwt-basic-auth'); + await button.trigger('click'); + + const args = springBootService.addBasicAuthJWT.getCall(0).args[0]; + expect(args).toEqual({ + baseName: 'beer', + folder: 'project/path', + projectName: 'Beer Project', + packageName: 'tech.jhipster.beer', + serverPort: 8080, + }); + }); + + it('should handle error on adding SpringBoot Security JWT Basic Auth failure', async () => { + const logger = stubLogger(); + const springBootService = stubSpringBootService(); + springBootService.addBasicAuthJWT.rejects({}); + await wrap({ springBootService, logger }); + const projectToUpdate: ProjectToUpdate = createProjectToUpdate(); + await fillFullForm(projectToUpdate); + await selectSection('springboot'); + + const initButton = wrapper.find('#springboot-jwt-basic-auth'); + await initButton.trigger('click'); + + const [message] = logger.error.getCall(0).args; + expect(message).toBe('Adding SpringBoot Security JWT Basic Auth to project failed'); + }); + it('should not add Angular when project path is not filled', async () => { const angularService = stubAngularService(); angularService.add.resolves({});