Repository: jhipster/generator-jhipster (ts)

Issue:
k8s sub-gen generates too large PostgreSQL passwords
<!--
- Please follow the issue template below for bug reports.
- If you have a support request rather than a bug, please use [Stack Overflow](http://stackoverflow.com/questions/tagged/jhipster) with the JHipster tag.
- For bug reports it is mandatory to run the command `jhipster info` in your project's root folder, and paste the result here.
- Tickets opened without any of these pieces of information will be **closed** without any explanation.
-->

##### **Overview of the issue**

<!-- Explain the bug, if an error is being thrown a stack trace helps -->

When generating kubernetes files for applications using PostgreSQL, we generate a 256-byte long password. When those applications start in kubernetes, they are failing with a trace like this:

<details>
<summary>Stacktrace in failing Pod</summary>
<pre>
Caused by: org.postgresql.util.PSQLException: FATAL: password authentication failed for user "XXX"
	at org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:520)
	at org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:141)
	at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:192)
	at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49)
	at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:195)
	at org.postgresql.Driver.makeConnection(Driver.java:458)
	at org.postgresql.Driver.connect(Driver.java:260)
	at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:136)
	at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:369)
	at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:198)
	at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:467)
	at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:541)
	at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:115)
	at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112)
	at com.zaxxer.hikari.HikariDataSource$$FastClassBySpringCGLIB$$eeb1ae86.invoke(<generated>)
	at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
	at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:750)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
	at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:136)
	at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:124)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
	at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:689)
	at com.zaxxer.hikari.HikariDataSource$$EnhancerBySpringCGLIB$$3645ec0f.getConnection(<generated>)
	at liquibase.integration.spring.SpringLiquibase.afterPropertiesSet(SpringLiquibase.java:302)
	... 26 common frames omitted
</pre>
</details>

The reason for this issue is that *identifiers* in PSQL are limited by a length of 63 bytes. See https://stackoverflow.com/questions/19499058/pgsql-character-limitations

##### **Reproduce the error**

<!-- For bug reports, an unambiguous set of steps to reproduce the error -->
1. generate an application, which uses PostgresSQL as prod database
2. use `jhipster kubernetes[-helm]` to generate k8s manifest
3. examine the logs of the failing application container


##### **Suggest a Fix**

<!-- If you can't fix the bug yourself, perhaps you can point to what might be
  causing the problem (line of code or commit) -->

Limit password length for PSQL to 63 or less bytes.

##### **JHipster Version(s)**
6.5.0 and master
<!--
Which version of JHipster are you using, is it a regression?
-->

##### **JHipster configuration**

<!--
To provide all information we need, you should run `jhipster info` in the project root folder, and
copy/paste the result here.
The `.yo-rc.json` file generated in the root folder is mandatory for bug reports. This will help us to replicate the scenario.
You should remove any sensitive information like the rememberMe key or the jwtSecretKey key.
---
If you have a JDL please wrap it in below structure
  <details>
  <summary>JDL definitions</summary>
  <pre>
     JDL content here
  </pre>
  </details>
-->

##### **Entity configuration(s) `entityName.json` files generated in the `.jhipster` directory**

<!--
If the error is during an entity creation or associated with a specific entity.
If you are using JDL, please share that configuration as well.
-->

##### **Browsers and Operating System**

<!-- What OS are you on? is this a problem with all browsers or only IE8? -->

-   [X] Checking this box is mandatory (this is just to show you read everything)

<!-- Love JHipster? Please consider supporting our collective:
👉  https://opencollective.com/generator-jhipster/donate -->


Pull request description:
reduces db-password size to prevent fail in k8s
sets the size of db generated passwords in a way, so the resulting password is 60 bytes long and not causing failures for PostgreSQL apps

fix #10803

-   Please make sure the below checklist is followed for Pull Requests.

-   [ ] [All continuous integration tests](https://github.com/jhipster/generator-jhipster/actions) are green
-   [ ] Tests are added where necessary
-   [ ] Documentation is added/updated where necessary
-   [ ] Coding Rules & Commit Guidelines as per our [CONTRIBUTING.md document](https://github.com/jhipster/generator-jhipster/blob/master/CONTRIBUTING.md) are followed

<!--
Please also reference the issue number in a commit message to [automatically close the related Github issue](https://help.github.com/articles/closing-issues-via-commit-messages/)

Note: It is also possible to add `[skip ci]` to your commit message to skip Travis tests
-->


Patch:
diff --git a/generators/cleanup.js b/generators/cleanup.js
index a805e32cc3..691440720b 100644
--- a/generators/cleanup.js
+++ b/generators/cleanup.js
@@ -212,4 +212,7 @@ function cleanupOldServerFiles(generator, javaDir, testDir, mainResourceDir, tes
         generator.config.delete('blueprint');
         generator.config.delete('blueprintVersion');
     }
+    if (generator.isJhipsterVersionLessThan('6.5.2')) {
+        generator.removeFile(`${testDir}web/rest/ClientForwardControllerIT.java`);
+    }
 }
diff --git a/generators/client/templates/react/src/main/webapp/app/modules/login/logout.tsx.ejs b/generators/client/templates/react/src/main/webapp/app/modules/login/logout.tsx.ejs
index 2c8c50d317..1daf106d09 100644
--- a/generators/client/templates/react/src/main/webapp/app/modules/login/logout.tsx.ejs
+++ b/generators/client/templates/react/src/main/webapp/app/modules/login/logout.tsx.ejs
@@ -16,7 +16,7 @@
  See the License for the specific language governing permissions and
  limitations under the License.
 -%>
-import React from 'react';
+import React, { useLayoutEffect } from 'react';
 import { connect } from 'react-redux';
 
 import { IRootState } from 'app/shared/reducers';
@@ -27,29 +27,25 @@ export interface ILogoutProps extends StateProps, DispatchProps {
   logoutUrl: string;
 }
 
-export class Logout extends React.Component<ILogoutProps> {
-
-  componentDidMount() {
-    this.props.logout();
-  }
-
-  render() {
-    const logoutUrl = this.props.logoutUrl;
+export const Logout = (props: ILogoutProps) => {
+  useLayoutEffect(() => {
+    props.logout();
+    const logoutUrl = props.logoutUrl;
     if (logoutUrl) {
       // if Keycloak, logoutUrl has protocol/openid-connect in it
-      window.location.href = logoutUrl.includes('/protocol') ?
-        logoutUrl + '?redirect_uri=' + window.location.origin :
-        logoutUrl + '?id_token_hint=' + this.props.idToken +
-          '&post_logout_redirect_uri=' + window.location.origin;
+      window.location.href =
+        logoutUrl.includes('/protocol')
+          ? logoutUrl + '?redirect_uri=' + window.location.origin
+          : logoutUrl + '?id_token_hint=' + props.idToken + '&post_logout_redirect_uri=' + window.location.origin;
     }
-
-    return (
-      <div className="p-5">
-        <h4>Logged out successfully!</h4>
-      </div>
-    );
-  }
-}
+  });
+
+  return (
+    <div className="p-5">
+      <h4>Logged out successfully!</h4>
+    </div>
+  );
+};
 
 const mapStateToProps = (storeState: IRootState) => ({
   logoutUrl: storeState.authentication.logoutUrl,
diff --git a/generators/entity-server/templates/src/main/resources/config/liquibase/changelog/added_entity.xml.ejs b/generators/entity-server/templates/src/main/resources/config/liquibase/changelog/added_entity.xml.ejs
index 8bd38de5cc..af042a74d4 100644
--- a/generators/entity-server/templates/src/main/resources/config/liquibase/changelog/added_entity.xml.ejs
+++ b/generators/entity-server/templates/src/main/resources/config/liquibase/changelog/added_entity.xml.ejs
@@ -33,8 +33,9 @@
                 break;
             }
         }
+        const isAutoIncrementDB = prodDatabaseType === 'mysql' || prodDatabaseType === 'mariadb';
     _%>
-    <%_ if (prodDatabaseType === 'mysql' || prodDatabaseType === 'mariadb') { _%>
+    <%_ if (isAutoIncrementDB) { _%>
     <property name="autoIncrement" value="<%- autoIncrementValue %>"/>
     <%_ } _%>
 
@@ -47,7 +48,7 @@
         <%_ } else { _%>
         <createTable tableName="<%= entityTableName %>" remarks="<%- formatAsLiquibaseRemarks(javadoc) %>">
         <%_ } _%>
-            <column name="id" type="<%= primaryKeyType %>" <%_ if (primaryKeyType === 'varchar(100)' ) { _%> > <% } else { %> autoIncrement="${autoIncrement}"> <%_ } %>
+            <column name="id" type="<%= primaryKeyType %>" <%_ if (primaryKeyType === 'varchar(100)' ) { _%> <% } else if (isAutoIncrementDB) { %> autoIncrement="${autoIncrement}" <%_ } %>>
                 <constraints primaryKey="true" nullable="false"/>
             </column>
             <%_ for (idx in fields) {
diff --git a/generators/kubernetes-base.js b/generators/kubernetes-base.js
index a43f334b35..3f29ab5176 100644
--- a/generators/kubernetes-base.js
+++ b/generators/kubernetes-base.js
@@ -68,7 +68,7 @@ function loadConfig() {
     this.ingressType = this.config.get('ingressType');
     this.ingressDomain = this.config.get('ingressDomain');
     this.istio = this.config.get('istio');
-    this.dbRandomPassword = crypto.randomBytes(128).toString('hex');
+    this.dbRandomPassword = crypto.randomBytes(30).toString('hex');
 }
 
 function saveConfig() {
diff --git a/generators/server/files.js b/generators/server/files.js
index 26db0912d6..2cac1790aa 100644
--- a/generators/server/files.js
+++ b/generators/server/files.js
@@ -1247,8 +1247,8 @@ const serverFiles = {
             path: SERVER_TEST_SRC_DIR,
             templates: [
                 {
-                    file: 'package/web/rest/ClientForwardControllerIT.java',
-                    renameTo: generator => `${generator.testDir}web/rest/ClientForwardControllerIT.java`
+                    file: 'package/web/rest/ClientForwardControllerTest.java',
+                    renameTo: generator => `${generator.testDir}web/rest/ClientForwardControllerTest.java`
                 }
             ]
         },
diff --git a/generators/server/templates/build.gradle.ejs b/generators/server/templates/build.gradle.ejs
index 0fb006645d..ed08be585a 100644
--- a/generators/server/templates/build.gradle.ejs
+++ b/generators/server/templates/build.gradle.ejs
@@ -534,15 +534,9 @@ task cleanResources(type: Delete) {
     delete "build/resources"
 }
 
-<%_ if (enableSwaggerCodegen) { _%>
-wrapper {
-    gradleVersion = "5.6.4"
-}
-<%_ } else { _%>
 wrapper {
     gradleVersion = "<%= GRADLE_VERSION %>"
 }
-<%_ } _%>
 
 <%_ if (!skipClient) { _%>
 
diff --git a/generators/server/templates/gradle.properties.ejs b/generators/server/templates/gradle.properties.ejs
index cd96d0d469..1f66c9199d 100644
--- a/generators/server/templates/gradle.properties.ejs
+++ b/generators/server/templates/gradle.properties.ejs
@@ -64,7 +64,7 @@ liquibase_plugin_version=2.0.1
 <%_ } _%>
 sonarqube_plugin_version=2.8
 <%_ if (enableSwaggerCodegen) { _%>
-openapi_plugin_version=4.2.0
+openapi_plugin_version=4.2.1
 <%_ } _%>
 spring_no_http_plugin_version=0.0.3.RELEASE
 checkstyle_version=8.24
diff --git a/generators/server/templates/gradle/wrapper/gradle-wrapper.properties.ejs b/generators/server/templates/gradle/wrapper/gradle-wrapper.properties.ejs
index 00accbeb55..441ac4e3c6 100644
--- a/generators/server/templates/gradle/wrapper/gradle-wrapper.properties.ejs
+++ b/generators/server/templates/gradle/wrapper/gradle-wrapper.properties.ejs
@@ -1,9 +1,5 @@
 distributionBase=GRADLE_USER_HOME
 distributionPath=wrapper/dists
-<%_ if (enableSwaggerCodegen) { _%>
-distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-bin.zip
-<%_ } else { _%>
 distributionUrl=https\://services.gradle.org/distributions/gradle-<%= GRADLE_VERSION %>-bin.zip
-<%_ } _%>
 zipStoreBase=GRADLE_USER_HOME
 zipStorePath=wrapper/dists
diff --git a/generators/server/templates/pom.xml.ejs b/generators/server/templates/pom.xml.ejs
index fa364cbed5..5debaad0e1 100644
--- a/generators/server/templates/pom.xml.ejs
+++ b/generators/server/templates/pom.xml.ejs
@@ -129,7 +129,7 @@
         <jib-maven-plugin.version><%= JIB_VERSION %></jib-maven-plugin.version>
         <lifecycle-mapping.version>1.0.0</lifecycle-mapping.version>
 <%_ if (enableSwaggerCodegen) { _%>
-        <openapi-generator-maven-plugin.version>4.2.0</openapi-generator-maven-plugin.version>
+        <openapi-generator-maven-plugin.version>4.2.1</openapi-generator-maven-plugin.version>
 <%_ } _%>
         <properties-maven-plugin.version>1.0.0</properties-maven-plugin.version>
         <sonar-maven-plugin.version>3.7.0.1746</sonar-maven-plugin.version>
diff --git a/generators/server/templates/src/main/java/package/config/SecurityConfiguration.java.ejs b/generators/server/templates/src/main/java/package/config/SecurityConfiguration.java.ejs
index d646f3fd5b..02d9d91312 100644
--- a/generators/server/templates/src/main/java/package/config/SecurityConfiguration.java.ejs
+++ b/generators/server/templates/src/main/java/package/config/SecurityConfiguration.java.ejs
@@ -217,10 +217,8 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
         <%_ } _%>
     <%_ } _%>
             .exceptionHandling()
-    <%_ if (authenticationType !== 'oauth2') { _%>
-            .authenticationEntryPoint(problemSupport)
-    <%_ } _%>
-            .accessDeniedHandler(problemSupport)
+                .authenticationEntryPoint(problemSupport)
+                .accessDeniedHandler(problemSupport)
     <%_ if (authenticationType === 'session') { _%>
         <%_ if (!skipUserManagement) { _%>
         .and()
diff --git a/generators/server/templates/src/main/resources/config/liquibase/changelog/initial_schema.xml.ejs b/generators/server/templates/src/main/resources/config/liquibase/changelog/initial_schema.xml.ejs
index a4246dfc7a..e1b534be25 100644
--- a/generators/server/templates/src/main/resources/config/liquibase/changelog/initial_schema.xml.ejs
+++ b/generators/server/templates/src/main/resources/config/liquibase/changelog/initial_schema.xml.ejs
@@ -24,10 +24,13 @@
     xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.6.xsd
                         http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
 
-    <%_ if (prodDatabaseType === 'mysql' || prodDatabaseType === 'mariadb') { _%>
+    <% const isAutoIncrementDB = prodDatabaseType === 'mysql' || prodDatabaseType === 'mariadb';
+       const isSequenceDB = prodDatabaseType === 'postgresql' || prodDatabaseType === 'oracle' || prodDatabaseType === 'mssql';
+    _%>
+    <%_ if (isAutoIncrementDB) { _%>
     <property name="autoIncrement" value="true"/>
     <%_ } _%>
-    <%_ if (prodDatabaseType === 'postgresql' || prodDatabaseType === 'oracle' || prodDatabaseType === 'mssql') { _%>
+    <%_ if (isSequenceDB) { _%>
     <changeSet id="00000000000000" author="jhipster">
         <createSequence sequenceName="sequence_generator" startValue="1050" incrementBy="50"/>
     </changeSet>
@@ -45,7 +48,7 @@
                 <constraints primaryKey="true" nullable="false"/>
             </column>
             <%_ } else { _%>
-            <column name="id" type="bigint" autoIncrement="${autoIncrement}">
+            <column name="id" type="bigint" <% if (isAutoIncrementDB) { _%> autoIncrement="${autoIncrement}" <%_ } _%>>
                 <constraints primaryKey="true" nullable="false"/>
             </column>
             <%_ } _%>
@@ -172,7 +175,7 @@
     <%_ } _%>
 <%_ } _%>
         <createTable tableName="<%= jhiTablePrefix %>_persistent_audit_event">
-            <column name="event_id" type="bigint" autoIncrement="${autoIncrement}">
+            <column name="event_id" type="bigint" <% if (isAutoIncrementDB) { _%> autoIncrement="${autoIncrement}" <%_ } _%>>
                 <constraints primaryKey="true" nullable="false"/>
             </column>
             <column name="principal" type="varchar(50)">
@@ -215,7 +218,7 @@
 
     <changeSet author="jhipster" id="00000000000002" context="test">
         <createTable tableName="<%= jhiTablePrefix %>_date_time_wrapper">
-            <column autoIncrement="${autoIncrement}" name="id" type="BIGINT">
+            <column <% if (isAutoIncrementDB) { _%> autoIncrement="${autoIncrement}" <%_ } %> name="id" type="BIGINT">
                 <constraints primaryKey="true" primaryKeyName="<%= jhiTablePrefix %>_date_time_wrapperPK"/>
             </column>
             <column name="instant" type="timestamp"/>


Test patch:
diff --git a/generators/client/templates/angular/src/test/javascript/protractor.conf.js.ejs b/generators/client/templates/angular/src/test/javascript/protractor.conf.js.ejs
index c4fa8facf4..816033f5ed 100644
--- a/generators/client/templates/angular/src/test/javascript/protractor.conf.js.ejs
+++ b/generators/client/templates/angular/src/test/javascript/protractor.conf.js.ejs
@@ -57,7 +57,7 @@ exports.config = {
     },
 
     onPrepare: function() {
-        browser.driver.manage().window().setSize(1280, 1024);
+        browser.driver.manage().window().setSize(1280, 10240);
         // Disable animations
         // @ts-ignore
         browser.executeScript('document.body.className += " notransition";');
diff --git a/generators/entity-client/templates/react/src/test/javascript/e2e/entities/entity.spec.ts.ejs b/generators/entity-client/templates/react/src/test/javascript/e2e/entities/entity.spec.ts.ejs
index 6571a20c22..bcb188ea91 100644
--- a/generators/entity-client/templates/react/src/test/javascript/e2e/entities/entity.spec.ts.ejs
+++ b/generators/entity-client/templates/react/src/test/javascript/e2e/entities/entity.spec.ts.ejs
@@ -73,6 +73,8 @@ describe('<%= entityClass %> e2e test', () => {
         await signInPage.loginWithOAuth('admin', 'admin');
         <%_ } _%>
         await waitUntilDisplayed(navBarPage.entityMenu);
+        await waitUntilDisplayed(navBarPage.adminMenu);
+        await waitUntilDisplayed(navBarPage.accountMenu);
     });
 
     it('should load <%= entityClassPlural %>', async () => {
diff --git a/generators/server/templates/src/test/java/package/web/rest/ClientForwardControllerIT.java.ejs b/generators/server/templates/src/test/java/package/web/rest/ClientForwardControllerTest.java.ejs
similarity index 73%
rename from generators/server/templates/src/test/java/package/web/rest/ClientForwardControllerIT.java.ejs
rename to generators/server/templates/src/test/java/package/web/rest/ClientForwardControllerTest.java.ejs
index f99b19a1bb..e499650a8a 100644
--- a/generators/server/templates/src/test/java/package/web/rest/ClientForwardControllerIT.java.ejs
+++ b/generators/server/templates/src/test/java/package/web/rest/ClientForwardControllerTest.java.ejs
@@ -18,22 +18,8 @@
 -%>
 package <%=packageName%>.web.rest;
 
-<%_ if (databaseType === 'cassandra') { _%>
-import <%= packageName %>.AbstractCassandraTest;
-<%_ } _%>
-<%_ if (cacheProvider === 'redis') { _%>
-import <%=packageName%>.RedisTestContainerExtension;
-<%_ } _%>
-import <%=packageName%>.<%= mainClass %>;
-<%_ if (authenticationType === 'oauth2') { _%>
-import <%=packageName%>.config.TestSecurityConfiguration;
-<%_ } _%>
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
-<%_ if (cacheProvider === 'redis') { _%>
-import org.junit.jupiter.api.extension.ExtendWith;
-<%_ } _%>
-import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.http.MediaType;
 import org.springframework.test.web.servlet.MockMvc;
 import org.springframework.test.web.servlet.ResultActions;
@@ -47,17 +33,9 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
 import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
 
 /**
- * Integration tests for the {@link ClientForwardController} REST controller.
+ * Unit tests for the {@link ClientForwardController} REST controller.
  */
-<%_ if (authenticationType === 'oauth2') { _%>
-@SpringBootTest(classes = {<%= mainClass %>.class, TestSecurityConfiguration.class})
-<%_ } else { _%>
-@SpringBootTest(classes = <%= mainClass %>.class)
-<%_ } _%>
-<%_ if (cacheProvider === 'redis') { _%>
-@ExtendWith(RedisTestContainerExtension.class)
-<%_ } _%>
-public class ClientForwardControllerIT <% if (databaseType === 'cassandra') { %>extends AbstractCassandraTest <% } %>{
+public class ClientForwardControllerTest {
 
     private MockMvc restMockMvc;