Skip to content

Commit

Permalink
Ensure password gen feature flag is respected
Browse files Browse the repository at this point in the history
Signed-off-by: Emanuele Feliziani <[email protected]>
  • Loading branch information
GioSensation committed Apr 9, 2024
1 parent b88d3f6 commit 4c16e52
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 24 deletions.
21 changes: 16 additions & 5 deletions dist/autofill-debug.js

Large diffs are not rendered by default.

21 changes: 16 additions & 5 deletions dist/autofill.js

Large diffs are not rendered by default.

16 changes: 12 additions & 4 deletions src/Settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,18 @@ export class Settings {
* @param {{
* mainType: SupportedMainTypes
* subtype: import('./Form/matching.js').SupportedSubTypes | "unknown"
* variant?: import('./Form/matching.js').SupportedVariants | ""
* }} types
* @returns {boolean}
*/
isTypeUnavailable ({mainType, subtype}) {
isTypeUnavailable ({mainType, subtype, variant}) {
if (mainType === 'unknown') return true

// Ensure password generation feature flag is respected
if (subtype === 'password' && variant === 'new') {
return !this.featureToggles.password_generation
}

if (!this.featureToggles[`inputType_${mainType}`] && subtype !== 'emailAddress') {
return true
}
Expand All @@ -201,11 +208,12 @@ export class Settings {
* @param {{
* mainType: SupportedMainTypes
* subtype: import('./Form/matching.js').SupportedSubTypes | "unknown"
* variant?: import('./Form/matching.js').SupportedVariants | ""
* }} types
* @returns {Promise<boolean>}
*/
async populateDataIfNeeded ({mainType, subtype}) {
if (this.isTypeUnavailable({mainType, subtype})) return false
async populateDataIfNeeded ({mainType, subtype, variant}) {
if (this.isTypeUnavailable({mainType, subtype, variant})) return false
if (this.availableInputTypes?.[mainType] === undefined) {
await this.populateData()
return true
Expand All @@ -225,7 +233,7 @@ export class Settings {
* @returns {boolean}
*/
canAutofillType ({mainType, subtype, variant}, inContextSignup) {
if (this.isTypeUnavailable({ mainType, subtype })) return false
if (this.isTypeUnavailable({ mainType, subtype, variant })) return false

// If it's an email field and Email Protection is enabled, return true regardless of other options
const isEmailProtectionEnabled = this.featureToggles.emailProtection && this.availableInputTypes.email
Expand Down
11 changes: 11 additions & 0 deletions src/Settings.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,17 @@ describe('Settings', () => {
expect(settings.canAutofillType({ mainType: 'credentials', subtype: 'password', variant: 'current' }, null)).toBe(false)
}
],
[
{ password_generation: false },
{
...createAvailableInputTypes({
credentials: {username: true, password: true}
})
},
(settings) => {
expect(settings.canAutofillType({ mainType: 'credentials', subtype: 'password', variant: 'new' }, null)).toBe(false)
}
],
[
{},
{
Expand Down
21 changes: 16 additions & 5 deletions swift-package/Resources/assets/autofill-debug.js

Large diffs are not rendered by default.

21 changes: 16 additions & 5 deletions swift-package/Resources/assets/autofill.js

Large diffs are not rendered by default.

0 comments on commit 4c16e52

Please sign in to comment.