Skip to content

Commit

Permalink
Merge pull request #1446 from pascalgrimaud/front-security-jwt-basic-…
Browse files Browse the repository at this point in the history
…auth

Front: add security JWT basic auth button
  • Loading branch information
pascalgrimaud authored Apr 23, 2022
2 parents 3ad6dab + b23851a commit a372b8e
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/main/webapp/app/springboot/primary/Generator.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ export default defineComponent({
}
};

const addSpringBootSecurityJWTBasicAuth = async (): Promise<void> => {
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<void> => {
if (project.value.folder !== '') {
if (isAngularWithStyle.value) {
Expand Down Expand Up @@ -151,6 +159,7 @@ export default defineComponent({
addSpringBoot,
addSpringBootMvcTomcat,
addSpringBootSecurityJWT,
addSpringBootSecurityJWTBasicAuth,
addAngular,
addReact,
addVue,
Expand Down
9 changes: 9 additions & 0 deletions src/main/webapp/app/springboot/primary/Generator.vue
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,15 @@
>
Security JWT
</button>

<button
id="springboot-jwt-basic-auth"
class="btn btn-outline-primary"
:data-selector="selectorPrefix + '.add-spring-boot-jwt-basic-auth-button'"
@click.prevent="addSpringBootSecurityJWTBasicAuth"
>
Security JWT Basic Auth
</button>
</div>
<div
v-if="client === 'angular'"
Expand Down
1 change: 1 addition & 0 deletions src/test/javascript/cypress/integration/Generator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ describe('Generator', () => {
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', () => {
Expand Down
55 changes: 55 additions & 0 deletions src/test/javascript/spec/springboot/primary/Generator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({});
Expand Down

0 comments on commit a372b8e

Please sign in to comment.