Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generation: ensure password gen feature flag is respected #583

Merged
merged 1 commit into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions dist/autofill-debug.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 15 additions & 4 deletions dist/autofill.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 12 additions & 4 deletions src/Settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,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 @@ -223,11 +230,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 @@ -247,7 +255,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
19 changes: 15 additions & 4 deletions swift-package/Resources/assets/autofill-debug.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 15 additions & 4 deletions swift-package/Resources/assets/autofill.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading