Skip to content

Commit

Permalink
Merge pull request #2029 from marioneyraud/front-springdoc-security-j…
Browse files Browse the repository at this point in the history
…wt-button

Front: add springdoc security jwt button
  • Loading branch information
pascalgrimaud authored Jun 10, 2022
2 parents 3cced80 + 546a202 commit 8eb9e4c
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/main/webapp/app/common/domain/Service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export enum Service {
SPRING_DOC = 'SPRING_DOC',
SPRINGBOOT_JWT = 'SPRINGBOOT_JWT',
SPRINGBOOT_JWT_WITH_BASIC_AUTHENTICATION = 'SPRINGBOOT_JWT_WITH_BASIC_AUTHENTICATION',
SPRINGDOC_OPENAPI_WITH_SECURIITY_JWT = 'SPRINGDOC_OPENAPI_WITH_SECURIITY_JWT',
SPRINGBOOT_OAUTH2 = 'SPRINGBOOT_OAUTH2',
SPRINGBOOT_OAUTH2_ACCOUNT = 'SPRINGBOOT_OAUTH2_ACCOUNT',
SPRINGBOOT_MVC_WITH_TOMCAT = 'SPRINGBOOT_MVC_WITH_TOMCAT',
Expand Down
1 change: 1 addition & 0 deletions src/main/webapp/app/common/secondary/RestServiceId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const SERVICES: Record<string, Service> = {
'springdoc-openapi': Service.SPRING_DOC,
'springboot-jwt': Service.SPRINGBOOT_JWT,
'springboot-jwt-basic-auth': Service.SPRINGBOOT_JWT_WITH_BASIC_AUTHENTICATION,
'springdoc-openapi-with-security-jwt': Service.SPRINGDOC_OPENAPI_WITH_SECURIITY_JWT,
'springboot-oauth2': Service.SPRINGBOOT_OAUTH2,
'springboot-oauth2-account': Service.SPRINGBOOT_OAUTH2_ACCOUNT,
'springboot-tomcat': Service.SPRINGBOOT_MVC_WITH_TOMCAT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export type ServiceProjection =
| 'spring-doc'
| 'spring-boot-jwt'
| 'spring-boot-jwt-with-basic-authentication'
| 'springdoc-openapi-with-security-jwt'
| 'spring-boot-oauth2'
| 'spring-boot-oauth2-account'
| 'spring-boot-mvc-with-tomcat'
Expand Down Expand Up @@ -72,6 +73,7 @@ const SERVICES_PROJECTION: Record<Service, ServiceProjection> = {
[Service.SPRING_DOC]: 'spring-doc',
[Service.SPRINGBOOT_JWT]: 'spring-boot-jwt',
[Service.SPRINGBOOT_JWT_WITH_BASIC_AUTHENTICATION]: 'spring-boot-jwt-with-basic-authentication',
[Service.SPRINGDOC_OPENAPI_WITH_SECURIITY_JWT]: 'springdoc-openapi-with-security-jwt',
[Service.SPRINGBOOT_OAUTH2]: 'spring-boot-oauth2',
[Service.SPRINGBOOT_OAUTH2_ACCOUNT]: 'spring-boot-oauth2-account',
[Service.SPRINGBOOT_MVC_WITH_TOMCAT]: 'spring-boot-mvc-with-tomcat',
Expand Down Expand Up @@ -117,6 +119,7 @@ const SERVICES: Record<ServiceProjection, Service> = {
'spring-doc': Service.SPRING_DOC,
'spring-boot-jwt': Service.SPRINGBOOT_JWT,
'spring-boot-jwt-with-basic-authentication': Service.SPRINGBOOT_JWT_WITH_BASIC_AUTHENTICATION,
'springdoc-openapi-with-security-jwt': Service.SPRINGDOC_OPENAPI_WITH_SECURIITY_JWT,
'spring-boot-oauth2': Service.SPRINGBOOT_OAUTH2,
'spring-boot-oauth2-account': Service.SPRINGBOOT_OAUTH2_ACCOUNT,
'spring-boot-mvc-with-tomcat': Service.SPRINGBOOT_MVC_WITH_TOMCAT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,15 @@ export default defineComponent({
}
};

const addSpringDocOpenApiSecurityJWT = async (): Promise<void> => {
if (props.project.folder !== '') {
await springBootService
.addSpringdocJWT(toProject(props.project as ProjectToUpdate))
.then(() => alertBus.success('SpringDoc Open Api with Security JWT successfully added'))
.catch(error => alertBus.error(`Adding SpringDoc Open Api with Security JWT to project failed ${error}`));
}
};

const addSpringBootSecurityOAuth2 = async (): Promise<void> => {
if (props.project.folder !== '') {
await springBootService
Expand Down Expand Up @@ -245,6 +254,7 @@ export default defineComponent({
addSpringBootLogstash,
addSpringBootSecurityJWT,
addSpringBootSecurityJWTBasicAuth,
addSpringDocOpenApiSecurityJWT,
addSpringBootSecurityOAuth2,
addSpringBootSecurityOAuth2Account,
addPostgreSQL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@
:selector-prefix="selectorPrefix"
@click.prevent="addSpringBootSecurityJWTBasicAuth"
/>
<GeneratorButtonVue
:label="'SpringDoc OpenApi with Security JWT'"
:service="'springdoc-openapi-with-security-jwt'"
:selector-prefix="selectorPrefix"
@click.prevent="addSpringDocOpenApiSecurityJWT"
/>
<GeneratorButtonVue
:label="'Security OAuth2'"
:service="'spring-boot-oauth2'"
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 @@ -45,6 +45,7 @@ describe('Generator', () => {

cy.get(springBootGeneratorSelector('add-spring-boot-jwt-button')).contains('Security JWT');
cy.get(springBootGeneratorSelector('add-spring-boot-jwt-with-basic-authentication-button')).contains('Security JWT Basic Auth');
cy.get(springBootGeneratorSelector('add-springdoc-openapi-with-security-jwt-button')).contains('SpringDoc OpenApi with Security JWT');
cy.get(springBootGeneratorSelector('add-spring-boot-oauth2-button')).contains('Security OAuth2');
cy.get(springBootGeneratorSelector('add-spring-boot-oauth2-account-button')).contains('OAuth2 Account Context');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ describe('RestServiceId', () => {
expect(toService('springboot')).toEqual<Service>(Service.SPRINGBOOT);
expect(toService('springboot-jwt')).toEqual<Service>(Service.SPRINGBOOT_JWT);
expect(toService('springboot-jwt-basic-auth')).toEqual<Service>(Service.SPRINGBOOT_JWT_WITH_BASIC_AUTHENTICATION);
expect(toService('springdoc-openapi-with-security-jwt')).toEqual<Service>(Service.SPRINGDOC_OPENAPI_WITH_SECURIITY_JWT);
expect(toService('springboot-oauth2')).toEqual<Service>(Service.SPRINGBOOT_OAUTH2);
expect(toService('springboot-oauth2-account')).toEqual<Service>(Service.SPRINGBOOT_OAUTH2_ACCOUNT);
expect(toService('springboot-actuator')).toEqual<Service>(Service.SPRINGBOOT_ACTUATOR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ describe('ServiceProjection', () => {
expect(toServiceProjection(Service.SPRINGBOOT_ACTUATOR)).toEqual<ServiceProjection>('spring-boot-actuator');
expect(toServiceProjection(Service.SPRING_DOC)).toEqual<ServiceProjection>('spring-doc');
expect(toServiceProjection(Service.SPRINGBOOT_JWT)).toEqual<ServiceProjection>('spring-boot-jwt');
expect(toServiceProjection(Service.SPRINGDOC_OPENAPI_WITH_SECURIITY_JWT)).toEqual<ServiceProjection>(
'springdoc-openapi-with-security-jwt'
);
expect(toServiceProjection(Service.SPRINGBOOT_JWT_WITH_BASIC_AUTHENTICATION)).toEqual<ServiceProjection>(
'spring-boot-jwt-with-basic-authentication'
);
Expand Down Expand Up @@ -87,6 +90,7 @@ describe('ServiceProjection', () => {
expect(fromServiceProjection('spring-boot-jwt-with-basic-authentication')).toEqual<Service>(
Service.SPRINGBOOT_JWT_WITH_BASIC_AUTHENTICATION
);
expect(fromServiceProjection('springdoc-openapi-with-security-jwt')).toEqual<Service>(Service.SPRINGDOC_OPENAPI_WITH_SECURIITY_JWT);
expect(fromServiceProjection('spring-boot-mvc-with-tomcat')).toEqual<Service>(Service.SPRINGBOOT_MVC_WITH_TOMCAT);
expect(fromServiceProjection('spring-boot-dummy-feature')).toEqual<Service>(Service.SPRINGBOOT_DUMMY_FEATURE);
expect(fromServiceProjection('spring-boot-webflux-netty')).toEqual<Service>(Service.SPRINGBOOT_WEBFLUX_NETTY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,46 @@ describe('SpringBootGenerator', () => {
expectAlertErrorToBe(alertBus, 'Adding SpringBoot Security JWT Basic Auth to project failed error');
});

it('should not add SpringDoc open api with Security JWT when project path is not filled', async () => {
const springBootService = stubSpringBootService();
springBootService.addSpringdocJWT.resolves({});
await wrap({ springBootService, project: createProjectToUpdate({ folder: '' }) });

await component.addSpringDocOpenApiSecurityJWT();

expect(springBootService.addSpringdocJWT.called).toBe(false);
});

it('should add SpringDoc open api with Security JWT when project path is filled', async () => {
const springBootService = stubSpringBootService();
springBootService.addSpringdocJWT.resolves({});
const alertBus = stubAlertBus();
await wrap({ alertBus, springBootService, project: createProjectToUpdate({ folder: 'project/path' }) });

await component.addSpringDocOpenApiSecurityJWT();

const args = springBootService.addSpringdocJWT.getCall(0).args[0];
expect(args).toEqual({
baseName: 'beer',
folder: 'project/path',
projectName: 'Beer Project',
packageName: 'tech.jhipster.beer',
serverPort: 8080,
});
expectAlertSuccessToBe(alertBus, 'SpringDoc Open Api with Security JWT successfully added');
});

it('should handle error on adding SpringDoc open api with Security JWT failure', async () => {
const springBootService = stubSpringBootService();
springBootService.addSpringdocJWT.rejects('error');
const alertBus = stubAlertBus();
await wrap({ alertBus, springBootService, project: createProjectToUpdate({ folder: 'project/path' }) });

await component.addSpringDocOpenApiSecurityJWT();

expectAlertErrorToBe(alertBus, 'Adding SpringDoc Open Api with Security JWT to project failed error');
});

it('should not add SpringBoot Security OAuth2 when project path is not filled', async () => {
const springBootService = stubSpringBootService();
springBootService.addOAuth2.resolves({});
Expand Down

0 comments on commit 8eb9e4c

Please sign in to comment.