Repository navigation
fix: require the face to match the chip photo before issuing #80
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
2f6b5cd
fix: require the face to match the chip photo before issuing
jessevanmuijden 07b7e68
build(deps): bump golang.org/x/net to v0.60.0
jessevanmuijden a74b771
Merge main into fix/chip-photo-match
jessevanmuijden f52aa9c
Address review: chip face match range, strict type, privacy inventory
jessevanmuijden File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,148 @@ | ||
| package apiv1 | ||
|
|
||
| import ( | ||
| "errors" | ||
| "fmt" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
|
|
||
| "github.com/sirosfoundation/facetec-api/internal/facetec" | ||
| "github.com/sirosfoundation/facetec-api/internal/idverrors" | ||
| "github.com/sirosfoundation/facetec-api/internal/tenant" | ||
| ) | ||
|
|
||
| func intPtr(v int) *int { return &v } | ||
|
|
||
| func TestChipFaceRejection(t *testing.T) { | ||
| cases := []struct { | ||
| name string | ||
| level *int | ||
| min int | ||
| rejected bool | ||
| }{ | ||
| {"not reported", nil, 6, true}, | ||
| {"below the minimum", intPtr(5), 6, true}, | ||
| {"at the minimum", intPtr(6), 6, false}, | ||
| {"above the minimum", intPtr(9), 6, false}, | ||
| {"reported as 0", intPtr(0), 6, true}, | ||
| {"no minimum configured uses the default (6)", intPtr(5), 0, true}, | ||
| {"no minimum configured, at the default", intPtr(6), 0, false}, | ||
| {"stricter configured minimum", intPtr(7), 8, true}, | ||
| {"top of the scale", intPtr(10), 6, false}, | ||
| {"above the 0–10 scale", intPtr(11), 6, true}, | ||
| {"negative", intPtr(-1), 0, true}, | ||
| } | ||
| for _, tt := range cases { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| code, msg, rejected := chipFaceRejection(facetec.IDScanResult{ChipFaceMatchLevel: tt.level}, tt.min) | ||
| assert.Equal(t, tt.rejected, rejected) | ||
| if tt.rejected { | ||
| assert.Equal(t, idverrors.CodeChipPhotoMismatch, code) | ||
| assert.NotEmpty(t, msg) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| // completedScan is a /process-request final response with an authenticated | ||
| // chip, an unexpired document and the given face matches. | ||
| func completedScan(printedMatch int, chipMatch string) string { | ||
| chipField := "" | ||
| if chipMatch != "" { | ||
| chipField = fmt.Sprintf(`"matchLevelNFCToFaceMap": %s,`, chipMatch) | ||
| } | ||
| return fmt.Sprintf(`{ | ||
| "idScanResultsSoFar": { | ||
| "photoIDNextStepEnumInt": 4, | ||
| "matchLevel": %d, | ||
| %s | ||
| "nfcStatusEnumInt": 4, | ||
| "nfcAuthenticationStatusEnumInt": 4, | ||
| "mrzStatusEnumInt": 2, | ||
| "barcodeStatusEnumInt": 3, | ||
| "documentData": {"givenName": "Alice", "familyName": "Test", "documentType": "passport", "dateOfExpiry": "2099-12-31"} | ||
| } | ||
| }`, printedMatch, chipField) | ||
| } | ||
|
|
||
| // A genuine document whose printed photo was replaced by the user's own: the | ||
| // printed-photo match is excellent, the chip is authentic, but the face does | ||
| // not match the chip photo. Nothing may be issued. | ||
| func TestProcessRequest_PhotoSubstitution_Refused(t *testing.T) { | ||
| c := newTestClientForProcessRequest(t, completedScan(9, "2")) | ||
| ctx := tenant.WithStdContext(t.Context(), &tenant.Context{ID: "test-tenant", Policy: noRulesPolicy(t)}) | ||
|
|
||
| resp, err := c.ProcessRequest(ctx, provenSession(t, c, ctx)) | ||
| require.NoError(t, err) | ||
| assert.Equal(t, string(idverrors.CodeChipPhotoMismatch), resp.CredentialIssueErrCode) | ||
| assert.Empty(t, resp.TransactionID) | ||
| } | ||
|
|
||
| func TestProcessRequest_ChipFaceMatch(t *testing.T) { | ||
| cases := []struct { | ||
| name string | ||
| chipMatch string | ||
| minLevel int | ||
| want idverrors.Code | ||
| }{ | ||
| {"not reported", "", 0, idverrors.CodeChipPhotoMismatch}, | ||
| {"below the default minimum", "5", 0, idverrors.CodeChipPhotoMismatch}, | ||
| // Passing the gate reaches the (empty, rejecting) policy. | ||
| {"at the default minimum", "6", 0, idverrors.CodePolicyRejected}, | ||
| {"configured stricter minimum", "7", 8, idverrors.CodeChipPhotoMismatch}, | ||
| } | ||
| for _, tt := range cases { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| c := newTestClientForProcessRequest(t, completedScan(9, tt.chipMatch)) | ||
| c.cfg.FaceTec.MinChipFaceMatchLevel = tt.minLevel | ||
| ctx := tenant.WithStdContext(t.Context(), &tenant.Context{ID: "test-tenant", Policy: noRulesPolicy(t)}) | ||
|
|
||
| resp, err := c.ProcessRequest(ctx, provenSession(t, c, ctx)) | ||
| require.NoError(t, err) | ||
| assert.Equal(t, string(tt.want), resp.CredentialIssueErrCode) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| // The NFC gate runs first: a scan without a chip read is refused for that, | ||
| // not for the missing chip face match it implies. | ||
| func TestProcessRequest_ChipFaceGateAfterNFCGate(t *testing.T) { | ||
| c := newTestClientForProcessRequest(t, nfcSkippedPayload) | ||
| ctx := tenant.WithStdContext(t.Context(), &tenant.Context{ID: "test-tenant", Policy: noRulesPolicy(t)}) | ||
|
|
||
| resp, err := c.ProcessRequest(ctx, provenSession(t, c, ctx)) | ||
| require.NoError(t, err) | ||
| assert.Equal(t, string(idverrors.CodeNFCSkipped), resp.CredentialIssueErrCode) | ||
| } | ||
|
|
||
| func TestSubmitIDScan_ChipFaceMatch(t *testing.T) { | ||
| for _, tt := range []struct { | ||
| name string | ||
| chipMatch string | ||
| want idverrors.Code | ||
| }{ | ||
| {"not reported", "", idverrors.CodeChipPhotoMismatch}, | ||
| {"below the minimum", `"matchLevelNFCToFaceMap": 3,`, idverrors.CodeChipPhotoMismatch}, | ||
| {"passes, reaches the policy", `"matchLevelNFCToFaceMap": 8,`, idverrors.CodePolicyRejected}, | ||
| } { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| c, livenessID := newTestClientForIDScan(t, `{ | ||
| "success": true, | ||
| "faceMatchLevel": 9, | ||
| `+tt.chipMatch+` | ||
| "nfcVerified": true, | ||
| "mrzVerified": true, | ||
| "barcodeVerified": true, | ||
| "documentData": {"givenName": "Alice", "familyName": "Test", "documentType": "passport", "dateOfExpiry": "2099-12-31"} | ||
| }`) | ||
| ctx := tenant.WithStdContext(t.Context(), &tenant.Context{ID: "test-tenant", Policy: noRulesPolicy(t)}) | ||
|
|
||
| _, _, err := c.SubmitIDScan(ctx, livenessID, &facetec.IDScanRequest{}) | ||
| var idvErr *idverrors.Error | ||
| require.True(t, errors.As(err, &idvErr), "got %v", err) | ||
| assert.Equal(t, tt.want, idvErr.Code) | ||
| }) | ||
| } | ||
| } |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.