EnxDev commented on code in PR #39469:
URL: https://github.com/apache/superset/pull/39469#discussion_r3550079643


##########
superset-frontend/src/components/AuthDbPasswordPolicyIndicator.tsx:
##########
@@ -0,0 +1,202 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import {
+  css,
+  styled,
+  useTheme,
+  type SupersetTheme,
+} from '@apache-superset/core/theme';
+import { t } from '@apache-superset/core/translation';
+import {
+  Icons,
+  Popover,
+  Progress,
+  Typography,
+} from '@superset-ui/core/components';
+import {
+  AUTH_DB_BCRYPT_MAX_PASSWORD_BYTES,
+  AUTH_DB_DEFAULT_PASSWORD_POLICY,
+  AuthDbPasswordPolicy,
+  getAuthDbPasswordPolicyChecks,
+} from 'src/utils/generateAuthDbPassword';
+
+interface AuthDbPasswordPolicyIndicatorProps {
+  password: string;
+  policy?: AuthDbPasswordPolicy;
+}
+
+const StrengthWrapper = styled.div`
+  ${({ theme }) => css`
+    display: flex;
+    align-items: center;
+    gap: ${theme.sizeUnit * 2}px;
+  `}
+`;
+
+const StrengthBarContainer = styled.div`
+  ${({ theme }) => css`

Review Comment:
   do we need `theme` here? 



##########
superset-frontend/src/components/AuthDbPasswordPolicyIndicator.tsx:
##########
@@ -0,0 +1,202 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import {
+  css,
+  styled,
+  useTheme,
+  type SupersetTheme,
+} from '@apache-superset/core/theme';
+import { t } from '@apache-superset/core/translation';
+import {
+  Icons,
+  Popover,
+  Progress,
+  Typography,
+} from '@superset-ui/core/components';
+import {
+  AUTH_DB_BCRYPT_MAX_PASSWORD_BYTES,
+  AUTH_DB_DEFAULT_PASSWORD_POLICY,
+  AuthDbPasswordPolicy,
+  getAuthDbPasswordPolicyChecks,
+} from 'src/utils/generateAuthDbPassword';
+
+interface AuthDbPasswordPolicyIndicatorProps {
+  password: string;
+  policy?: AuthDbPasswordPolicy;
+}
+
+const StrengthWrapper = styled.div`
+  ${({ theme }) => css`
+    display: flex;
+    align-items: center;
+    gap: ${theme.sizeUnit * 2}px;
+  `}
+`;
+
+const StrengthBarContainer = styled.div`
+  ${({ theme }) => css`
+    flex: 1;
+    cursor: help;
+
+    .ant-progress {
+      margin-bottom: 0;
+    }
+  `}
+`;

Review Comment:
   do we have another soulution instead of using the css class? 



##########
superset-frontend/src/components/AuthDbPasswordPolicyIndicator.tsx:
##########
@@ -0,0 +1,202 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import {
+  css,
+  styled,
+  useTheme,
+  type SupersetTheme,
+} from '@apache-superset/core/theme';
+import { t } from '@apache-superset/core/translation';
+import {
+  Icons,
+  Popover,
+  Progress,
+  Typography,
+} from '@superset-ui/core/components';
+import {
+  AUTH_DB_BCRYPT_MAX_PASSWORD_BYTES,
+  AUTH_DB_DEFAULT_PASSWORD_POLICY,
+  AuthDbPasswordPolicy,
+  getAuthDbPasswordPolicyChecks,
+} from 'src/utils/generateAuthDbPassword';
+
+interface AuthDbPasswordPolicyIndicatorProps {
+  password: string;
+  policy?: AuthDbPasswordPolicy;
+}
+
+const StrengthWrapper = styled.div`
+  ${({ theme }) => css`
+    display: flex;
+    align-items: center;
+    gap: ${theme.sizeUnit * 2}px;
+  `}
+`;

Review Comment:
   would make sense to use the `<Flex />` component here? 
   



##########
superset-frontend/src/utils/generateAuthDbPassword.test.ts:
##########
@@ -0,0 +1,143 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import {
+  AUTH_DB_DEFAULT_PASSWORD_POLICY,
+  AUTH_DB_PASSWORD_MIN_LENGTH,
+  generateAuthDbPassword,
+  getAuthDbPasswordPolicyChecks,
+  getAuthDbPasswordPolicyError,
+  satisfiesDefaultAuthDbPasswordPolicy,
+} from './generateAuthDbPassword';
+
+test('generateAuthDbPassword returns policy-compliant passwords', () => {
+  for (let i = 0; i < 20; i += 1) {
+    const pwd = generateAuthDbPassword();
+    expect(Array.from(pwd).length).toBeGreaterThanOrEqual(
+      AUTH_DB_PASSWORD_MIN_LENGTH,
+    );
+    expect(satisfiesDefaultAuthDbPasswordPolicy(pwd)).toBe(true);
+  }
+});
+
+test('generateAuthDbPassword honors a custom minimum length policy', () => {
+  const policy = {
+    ...AUTH_DB_DEFAULT_PASSWORD_POLICY,
+    password_min_length: 20,
+  };
+  for (let i = 0; i < 10; i += 1) {
+    const pwd = generateAuthDbPassword(policy);
+    expect(Array.from(pwd).length).toBeGreaterThanOrEqual(20);
+    expect(getAuthDbPasswordPolicyError(pwd, policy)).toBeNull();
+  }
+});
+
+test('getAuthDbPasswordPolicyChecks counts Unicode code points for min 
length', () => {
+  const policy = {
+    ...AUTH_DB_DEFAULT_PASSWORD_POLICY,
+    password_min_length: 2,
+    password_require_uppercase: false,
+    password_require_lowercase: false,
+    password_require_digit: false,
+    password_require_special: false,
+    password_common_list_check: false,
+  };
+  expect(getAuthDbPasswordPolicyChecks('a😀', policy).minLength).toBe(true);
+  expect(getAuthDbPasswordPolicyChecks('😀', policy).minLength).toBe(false);
+});
+
+test('getAuthDbPasswordPolicyError respects disabled uppercase requirement', 
() => {
+  const policy = {
+    ...AUTH_DB_DEFAULT_PASSWORD_POLICY,
+    password_require_uppercase: false,
+  };
+  const password = 'abcdefghijklm1!';
+  expect(getAuthDbPasswordPolicyError(password, policy)).toBeNull();
+});
+
+test('getAuthDbPasswordPolicyError rejects bcrypt passwords over the byte 
limit', () => {
+  const password = `Aa1!${'x'.repeat(69)}`;
+  expect(getAuthDbPasswordPolicyError(password)).toMatch(/72 bytes/);
+});
+
+test('getAuthDbPasswordPolicyError skips bcrypt byte limit for argon2', () => {
+  const policy = {
+    ...AUTH_DB_DEFAULT_PASSWORD_POLICY,
+    password_hash_algorithm: 'argon2' as const,
+    password_require_uppercase: false,
+    password_require_lowercase: false,
+    password_require_digit: false,
+    password_require_special: false,
+    password_common_list_check: false,
+    password_min_length: 1,

Review Comment:
   Would it make sense to centralize this instead of repeating it in multiple 
places?
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to