bito-code-review[bot] commented on code in PR #39469:
URL: https://github.com/apache/superset/pull/39469#discussion_r3497233595


##########
superset-frontend/src/components/AuthDbPasswordPolicyIndicator.tsx:
##########
@@ -0,0 +1,189 @@
+/**
+ * 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_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;
+    }
+  `}
+`;
+
+const Checklist = styled.div`
+  ${({ theme }) => css`
+    min-width: ${theme.sizeUnit * 70}px;
+    display: flex;
+    flex-direction: column;
+    gap: ${theme.sizeUnit}px;
+  `}
+`;
+
+const ChecklistItem = styled.div`
+  ${({ theme }) => css`
+    display: flex;
+    align-items: center;
+    gap: ${theme.sizeUnit * 2}px;
+    font-size: ${theme.fontSize}px;
+  `}
+`;
+
+const requirementText = {
+  minLength: (minLength: number) => t('At least %s characters', minLength),
+  uppercase: t('Contains an uppercase letter'),
+  lowercase: t('Contains a lowercase letter'),
+  digit: t('Contains a digit'),
+  special: t('Contains a special character'),
+  commonPassword: t('Is not a common password'),
+};
+
+function getStrengthState(percent: number, theme: SupersetTheme) {
+  if (percent <= 33) {
+    return { color: theme.colorError, label: t('Very weak') };
+  }
+  if (percent <= 50) {
+    return { color: theme.colorWarningText, label: t('Weak') };
+  }
+  if (percent <= 67) {
+    return { color: theme.colorWarning, label: t('Medium') };
+  }
+  if (percent <= 83) {
+    return { color: theme.colorSuccess, label: t('Strong') };
+  }
+  return { color: theme.colorSuccessTextActive, label: t('Very strong') };
+}
+
+export default function AuthDbPasswordPolicyIndicator({
+  password,
+  policy = AUTH_DB_DEFAULT_PASSWORD_POLICY,
+}: AuthDbPasswordPolicyIndicatorProps) {
+  const theme = useTheme();
+  const checks = getAuthDbPasswordPolicyChecks(password, policy);
+  const hasPassword = password.length > 0;
+  const checklist = [
+    {
+      label: requirementText.minLength(policy.password_min_length),
+      passed: hasPassword && checks.minLength,
+    },
+    ...(policy.password_require_uppercase
+      ? [
+          {
+            label: requirementText.uppercase,
+            passed: hasPassword && checks.uppercase,
+          },
+        ]
+      : []),
+    ...(policy.password_require_lowercase
+      ? [
+          {
+            label: requirementText.lowercase,
+            passed: hasPassword && checks.lowercase,
+          },
+        ]
+      : []),
+    ...(policy.password_require_digit
+      ? [{ label: requirementText.digit, passed: hasPassword && checks.digit }]
+      : []),
+    ...(policy.password_require_special
+      ? [
+          {
+            label: requirementText.special,
+            passed: hasPassword && checks.special,
+          },
+        ]
+      : []),
+    ...(policy.password_common_list_check
+      ? [
+          {
+            label: requirementText.commonPassword,
+            passed: hasPassword && checks.commonPassword,
+          },
+        ]
+      : []),
+  ];
+  const passedChecks = checklist.filter(item => item.passed).length;
+  const percent = Math.round((passedChecks / checklist.length) * 100);
+  const strength = getStrengthState(percent, theme);
+
+  return (
+    <StrengthWrapper>
+      <Popover
+        trigger="hover"
+        placement="topLeft"
+        content={
+          <Checklist>
+            {checklist.map(item => (
+              <ChecklistItem key={item.label}>
+                {item.passed ? (
+                  <Icons.CheckCircleFilled iconColor="success" iconSize="m" />
+                ) : (
+                  <Icons.CloseCircleOutlined iconColor="danger" iconSize="m" />
+                )}
+                <Typography.Text>{item.label}</Typography.Text>
+              </ChecklistItem>
+            ))}
+          </Checklist>
+        }
+      >
+        <StrengthBarContainer>
+          <Progress
+            percent={percent}
+            showInfo={false}
+            strokeColor={strength.color}
+            size="small"
+          />
+        </StrengthBarContainer>
+      </Popover>
+      <Typography.Text type="secondary">{strength.label}</Typography.Text>
+    </StrengthWrapper>
+  );
+}

Review Comment:
   <div>
   
   
   <div id="suggestion">
   <div id="issue"><b>Missing unit tests for new component</b></div>
   <div id="fix">
   
   New component with business logic (strength calculation at lines 153-155, 
conditional checklist generation at lines 112-152) lacks unit test coverage. 
BITO.md rule [11730] requires comprehensive tests for new tools covering 
success paths, error scenarios, and edge cases. A component that visualizes 
password strength and validates policy requirements needs tests to verify 
correctness of the percentage and label logic.
   </div>
   
   
   </div>
   
   
   
   
   <small><i>Code Review Run #27f12a</i></small>
   </div>
   
   ---
   Should Bito avoid suggestions like this for future reviews? (<a 
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
   - [ ] Yes, avoid them



##########
superset-frontend/src/utils/generateAuthDbPassword.ts:
##########
@@ -0,0 +1,288 @@
+/**
+ * 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 { t } from '@apache-superset/core/translation';
+/**
+ * Client-side generator aligned with default ``AUTH_DB_CONFIG`` / Python
+ * ``superset.utils.auth_db_password`` (minimum length, character classes, 
common list).
+ * Keep ``AUTH_DB_COMMON_PASSWORDS`` in sync with ``_COMMON_PASSWORDS`` in 
that module.
+ */
+export const AUTH_DB_PASSWORD_MIN_LENGTH = 12;
+export interface AuthDbPasswordPolicy {
+  password_min_length: number;
+  password_require_uppercase: boolean;
+  password_require_lowercase: boolean;
+  password_require_digit: boolean;
+  password_require_special: boolean;
+  password_common_list_check: boolean;
+}
+
+export const AUTH_DB_DEFAULT_PASSWORD_POLICY: AuthDbPasswordPolicy = {
+  password_min_length: AUTH_DB_PASSWORD_MIN_LENGTH,
+  password_require_uppercase: true,
+  password_require_lowercase: true,
+  password_require_digit: true,
+  password_require_special: true,
+  password_common_list_check: true,
+};
+
+/**
+ * Lowercased entries; keep in sync with ``_COMMON_PASSWORDS`` in
+ * ``superset/utils/auth_db_password.py``. Sync is enforced by
+ * ``tests/unit_tests/utils/test_auth_db_password.py``.
+ */
+export const AUTH_DB_COMMON_PASSWORDS = new Set(
+  [
+    'password',
+    'password1',
+    'password123',
+    '123456',
+    '12345678',
+    '123456789',
+    'qwerty',
+    'abc123',
+    'monkey',
+    'letmein',
+    'trustno1',
+    'dragon',
+    'baseball',
+    'iloveyou',
+    'master',
+    'sunshine',
+    'ashley',
+    'bailey',
+    'shadow',
+    'superman',
+    'qazwsx',
+    'michael',
+    'football',
+    'welcome',
+    'jesus',
+    'ninja',
+    'mustang',
+    'password1!',
+    'admin',
+    'admin123',
+    'root',
+    'toor',
+    'guest',
+    'p@ssw0rd',
+    'Passw0rd',
+    'Password1',
+    'Password123',
+    'Welcome1',
+    'Qwerty123',
+  ].map(s => s.toLowerCase()),
+);
+
+const UPPER = 'ABCDEFGHJKLMNPQRSTUVWXYZ';
+const LOWER = 'abcdefghijkmnopqrstuvwxyz';
+const DIGIT = '23456789';
+const SPECIAL = '!@#$%^&*-_=+';
+const ALPHANUM = UPPER + LOWER + DIGIT;
+
+export interface AuthDbPasswordPolicyChecks {
+  minLength: boolean;
+  uppercase: boolean;
+  lowercase: boolean;
+  digit: boolean;
+  special: boolean;
+  commonPassword: boolean;
+}
+
+function getCodePointLength(text: string): number {
+  return Array.from(text).length;
+}
+
+/** Mirrors ``int(cfg.get("password_min_length", default))`` in 
auth_db_password.py. */
+function resolveAuthDbPasswordMinLength(
+  passwordMinLength: number | undefined | null,
+): number {
+  if (passwordMinLength === undefined || passwordMinLength === null) {
+    return AUTH_DB_PASSWORD_MIN_LENGTH;
+  }
+  const parsed = Number(passwordMinLength);
+  if (!Number.isFinite(parsed)) {
+    return AUTH_DB_PASSWORD_MIN_LENGTH;
+  }
+  return Math.trunc(parsed);
+}
+
+function secureRandomInt(maxExclusive: number): number {
+  if (maxExclusive <= 0) {
+    throw new Error('secureRandomInt: maxExclusive must be positive');
+  }
+  const cryptoObj = globalThis.crypto;
+  if (!cryptoObj?.getRandomValues) {
+    throw new Error(
+      'secureRandomInt: a Web Crypto implementation with getRandomValues ' +
+        'is required to generate passwords',
+    );
+  }
+  const maxUint32 = 0xffffffff;
+  const limit = maxUint32 - (maxUint32 % maxExclusive);
+  const buf = new Uint32Array(1);
+  let value: number;
+  do {
+    cryptoObj.getRandomValues(buf);
+    value = buf[0]!;
+  } while (value >= limit);
+  return value % maxExclusive;
+}
+
+function pick(pool: string): string {
+  return pool[secureRandomInt(pool.length)]!;
+}
+
+function shuffleInPlace(chars: string[]): void {
+  for (let i = chars.length - 1; i > 0; i -= 1) {
+    const j = secureRandomInt(i + 1);
+    const t = chars[i]!;
+    chars[i] = chars[j]!;
+    chars[j] = t;
+  }
+}
+
+function getRequiredCharacterPools(policy: AuthDbPasswordPolicy): string[] {
+  const pools: string[] = [];
+  if (policy.password_require_uppercase) {
+    pools.push(UPPER);
+  }
+  if (policy.password_require_lowercase) {
+    pools.push(LOWER);
+  }
+  if (policy.password_require_digit) {
+    pools.push(DIGIT);
+  }
+  if (policy.password_require_special) {
+    pools.push(SPECIAL);
+  }
+  return pools;
+}
+
+function getGenerationPool(policy: AuthDbPasswordPolicy): string {
+  let pool = '';
+  if (policy.password_require_uppercase) {
+    pool += UPPER;
+  }
+  if (policy.password_require_lowercase) {
+    pool += LOWER;
+  }
+  if (policy.password_require_digit) {
+    pool += DIGIT;
+  }
+  if (policy.password_require_special) {
+    pool += SPECIAL;
+  }
+  return pool || ALPHANUM + SPECIAL;
+}
+
+/** Returns rule-by-rule checks for default AUTH_DB password policy. */
+export function getAuthDbPasswordPolicyChecks(
+  password: string,
+  policy: AuthDbPasswordPolicy = AUTH_DB_DEFAULT_PASSWORD_POLICY,
+): AuthDbPasswordPolicyChecks {
+  const minLength = resolveAuthDbPasswordMinLength(policy.password_min_length);
+  return {
+    minLength: getCodePointLength(password) >= minLength,
+    uppercase: !policy.password_require_uppercase || /[A-Z]/.test(password),
+    lowercase: !policy.password_require_lowercase || /[a-z]/.test(password),
+    digit: !policy.password_require_digit || /\p{Nd}/u.test(password),

Review Comment:
   <div>
   
   
   <div id="suggestion">
   <div id="issue"><b>Digit-check regex divergence</b></div>
   <div id="fix">
   
   `digit` check uses Unicode-aware `\p{Nd}` (line 205) while backend uses 
ASCII-only `r"\d"` (`auth_db_password.py:211`). These differ on characters like 
`০` (Bengali zero). A password containing only non-ASCII digits would pass 
frontend but fail server validation.
   </div>
   
   
   </div>
   
   
   
   
   <small><i>Code Review Run #27f12a</i></small>
   </div>
   
   ---
   Should Bito avoid suggestions like this for future reviews? (<a 
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
   - [ ] Yes, avoid them



-- 
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