-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: sanitize future installation terms of use
- Loading branch information
Showing
16 changed files
with
67 additions
and
34 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 +1 @@ | ||
export type TermsOfUse = string | null | ||
export type TermsOfUse = string |
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
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,10 +1,10 @@ | ||
import { type TermsOfUse } from '../../../info/domain/models/TermsOfUse' | ||
import { DataverseInfoRepository } from '../repositories/DataverseInfoRepository' | ||
|
||
export function getTermsOfUse( | ||
export function getApiTermsOfUse( | ||
dataverseInfoRepository: DataverseInfoRepository | ||
): Promise<TermsOfUse> { | ||
return dataverseInfoRepository.getTermsOfUse().catch((error) => { | ||
return dataverseInfoRepository.getApiTermsOfUse().catch((error) => { | ||
throw error | ||
}) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import DOMPurify from 'dompurify' | ||
import { TermsOfUse } from '@/info/domain/models/TermsOfUse' | ||
|
||
export class JSTermsOfUseMapper { | ||
static toSanitizedTermsOfUse(jsTermsOfUse: TermsOfUse): TermsOfUse { | ||
DOMPurify.addHook('afterSanitizeAttributes', function (node) { | ||
// set all elements owning target to target=_blank and rel=noopener for security reasons. See https://developer.chrome.com/docs/lighthouse/best-practices/external-anchors-use-rel-noopener | ||
if ('target' in node) { | ||
node.setAttribute('target', '_blank') | ||
node.setAttribute('rel', 'noopener') | ||
} | ||
}) | ||
// DOMPurify docs 👉 https://github.com/cure53/DOMPurify | ||
const cleanedHTML = DOMPurify.sanitize(jsTermsOfUse, { USE_PROFILES: { html: true } }) | ||
|
||
return cleanedHTML | ||
} | ||
} |
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
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
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
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
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
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
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
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
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
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
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 |
---|---|---|
|
@@ -4,19 +4,23 @@ import { UserRepository } from '@/users/domain/repositories/UserRepository' | |
import { ValidTokenNotLinkedAccountForm } from '@/sections/sign-up/valid-token-not-linked-account-form/ValidTokenNotLinkedAccountForm' | ||
import { AuthContextMother } from '@tests/component/auth/AuthContextMother' | ||
import { UserDTO } from '@/users/domain/useCases/DTOs/UserDTO' | ||
import { TermsOfUseMother } from '@tests/component/info/models/TermsOfUseMother' | ||
import { JSTermsOfUseMapper } from '@/info/infrastructure/mappers/JSTermsOfUseMapper' | ||
|
||
const dataverseInfoRepository: DataverseInfoRepository = {} as DataverseInfoRepository | ||
const userRepository: UserRepository = {} as UserRepository | ||
|
||
const termsOfUseMock = 'Terms of use' | ||
const termsOfUseMock = TermsOfUseMother.create() | ||
const sanitizedTermsOfUseMock = JSTermsOfUseMapper.toSanitizedTermsOfUse(termsOfUseMock) | ||
|
||
const mockUserName = 'mockUserName' | ||
const mockFirstName = 'mockFirstName' | ||
const mockLastName = 'mockLastName' | ||
const mockEmail = '[email protected]' | ||
|
||
describe('ValidTokenNotLinkedAccountForm', () => { | ||
beforeEach(() => { | ||
dataverseInfoRepository.getTermsOfUse = cy.stub().resolves(termsOfUseMock) | ||
dataverseInfoRepository.getApiTermsOfUse = cy.stub().resolves(sanitizedTermsOfUseMock) | ||
userRepository.register = cy.stub().as('registerUser').resolves() | ||
}) | ||
|
||
|
@@ -51,7 +55,7 @@ describe('ValidTokenNotLinkedAccountForm', () => { | |
cy.findByLabelText('Given Name').should('have.value', mockFirstName) | ||
cy.findByLabelText('Family Name').should('have.value', mockLastName) | ||
cy.findByLabelText('Email').should('have.value', mockEmail) | ||
cy.findByText(termsOfUseMock).should('exist') | ||
cy.findByText('Terms of Use SPA dev').should('exist') | ||
}) | ||
|
||
it('renders the form fields with the correct default values when tokenData does not have preferred username, given name, family name and email', () => { | ||
|
@@ -79,7 +83,7 @@ describe('ValidTokenNotLinkedAccountForm', () => { | |
cy.findByLabelText('Given Name').should('have.value', '') | ||
cy.findByLabelText('Family Name').should('have.value', '') | ||
cy.findByLabelText('Email').should('have.value', '') | ||
cy.findByText(termsOfUseMock).should('exist') | ||
cy.findByText('Terms of Use SPA dev').should('exist') | ||
}) | ||
}) | ||
|
||
|
@@ -216,7 +220,7 @@ describe('ValidTokenNotLinkedAccountForm', () => { | |
}) | ||
|
||
it('shows no terms message when there are no terms of use', () => { | ||
dataverseInfoRepository.getTermsOfUse = cy.stub().resolves(null) | ||
dataverseInfoRepository.getApiTermsOfUse = cy.stub().resolves(null) | ||
|
||
cy.customMount( | ||
<AuthContext.Provider | ||
|
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