forked from bitwarden/clients
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Avoid to autofill with paper from another contact
If paper.cozyMetadata.sourceAccountIdentifier and contactEmail were undefined, it was considered as a paper from the contact even if it has no sense. I added multiple tests to improve the function safety.
- Loading branch information
Showing
2 changed files
with
121 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import { CozyProfile } from "../../apps/browser/src/autofill/services/abstractions/autofill.service"; | ||
|
||
import { selectDataWithCozyProfile } from "./mapping"; | ||
import { isPaperFromContact, selectDataWithCozyProfile } from "./mapping"; | ||
|
||
// PROFILES | ||
|
||
|
@@ -41,6 +41,111 @@ const WORK_ONLY_ELEMENT = { phone: "2", label: "work" }; | |
const WORK_AND_TYPE_ELEMENT = { phone: "3", label: "work", type: "Cozy Cloud" }; | ||
|
||
describe("mapping", () => { | ||
describe("isPaperFromContact", () => { | ||
it("should return true if referenced by same contact", () => { | ||
const paper = { | ||
relationships: { | ||
referenced_by: { | ||
data: [ | ||
{ | ||
id: "7a4a4166175d8bb5e69033669702390d", | ||
type: "io.cozy.contacts", | ||
}, | ||
], | ||
}, | ||
}, | ||
cozyMetadata: {}, | ||
}; | ||
|
||
expect( | ||
isPaperFromContact(paper, "7a4a4166175d8bb5e69033669702390d", "[email protected]", false), | ||
).toEqual(true); | ||
}); | ||
|
||
it("should return false if referenced by different contact", () => { | ||
const paper = { | ||
relationships: { | ||
referenced_by: { | ||
data: [ | ||
{ | ||
id: "9b2a1982738d8bb5e69033669700988a", | ||
type: "io.cozy.contacts", | ||
}, | ||
], | ||
}, | ||
}, | ||
cozyMetadata: {}, | ||
}; | ||
|
||
expect( | ||
isPaperFromContact(paper, "7a4a4166175d8bb5e69033669702390d", "[email protected]", false), | ||
).toEqual(false); | ||
}); | ||
|
||
it("should return true if source account id corresponds to email", () => { | ||
const paper = { | ||
relationships: {}, | ||
cozyMetadata: { | ||
sourceAccountIdentifier: "[email protected]", | ||
}, | ||
}; | ||
|
||
expect( | ||
isPaperFromContact(paper, "7a4a4166175d8bb5e69033669702390d", "[email protected]", false), | ||
).toEqual(true); | ||
}); | ||
|
||
it("should return false if source account id does not correspond email", () => { | ||
const paper = { | ||
relationships: {}, | ||
cozyMetadata: { | ||
sourceAccountIdentifier: "john123", | ||
}, | ||
}; | ||
|
||
expect( | ||
isPaperFromContact(paper, "7a4a4166175d8bb5e69033669702390d", "[email protected]", false), | ||
).toEqual(false); | ||
}); | ||
|
||
it("should return false if source account id is undefined and email is undefined", () => { | ||
const paper = { | ||
relationships: {}, | ||
cozyMetadata: {}, | ||
}; | ||
|
||
expect( | ||
isPaperFromContact(paper, "7a4a4166175d8bb5e69033669702390d", undefined, false), | ||
).toEqual(false); | ||
}); | ||
|
||
it("should return true if paper from konnector and contact is 'me'", () => { | ||
const paper = { | ||
relationships: {}, | ||
cozyMetadata: { | ||
sourceAccount: "123", | ||
}, | ||
}; | ||
|
||
expect( | ||
isPaperFromContact(paper, "7a4a4166175d8bb5e69033669702390d", "[email protected]", true), | ||
).toEqual(true); | ||
}); | ||
|
||
it("should return false if paper from konnector and contact is not 'me'", () => { | ||
const paper = { | ||
relationships: {}, | ||
cozyMetadata: { | ||
sourceAccount: "123", | ||
}, | ||
}; | ||
|
||
expect( | ||
isPaperFromContact(paper, "7a4a4166175d8bb5e69033669702390d", "[email protected]", false), | ||
).toEqual(false); | ||
}); | ||
}); | ||
|
||
describe("selectDataWithCozyProfile", () => { | ||
describe("with no element", () => { | ||
it("should handle undefined array", () => { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters