This repository has been archived by the owner on Sep 11, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 832
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Device manager - security recommendations section (PSG-639) (#9179)
* display inactive status on device tile * unify DeviceSecurityVariation type, add correct icon to inactive ui * move types into type file * move DeviceSecurityVariation into types * add security recommendations section * add view all stubbed buttons * undeo debug * test security recs * remove debug * use css for card spacing
- Loading branch information
Kerry
committed
Aug 15, 2022
1 parent
9eaf48b
commit 0c5ad45
Showing
15 changed files
with
518 additions
and
16 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
19 changes: 19 additions & 0 deletions
19
res/css/components/views/settings/devices/_SecurityRecommendations.pcss
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,19 @@ | ||
/* | ||
Copyright 2022 The Matrix.org Foundation C.I.C. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
.mx_SecurityRecommendations_spacing { | ||
height: $spacing-16; | ||
} |
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
100 changes: 100 additions & 0 deletions
100
src/components/views/settings/devices/SecurityRecommendations.tsx
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,100 @@ | ||
/* | ||
Copyright 2022 The Matrix.org Foundation C.I.C. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
import React from 'react'; | ||
|
||
import { _t } from '../../../../languageHandler'; | ||
import AccessibleButton from '../../elements/AccessibleButton'; | ||
import SettingsSubsection from '../shared/SettingsSubsection'; | ||
import DeviceSecurityCard from './DeviceSecurityCard'; | ||
import { filterDevicesBySecurityRecommendation, INACTIVE_DEVICE_AGE_MS } from './filter'; | ||
import { DevicesDictionary, DeviceSecurityVariation } from './types'; | ||
|
||
interface Props { | ||
devices: DevicesDictionary; | ||
} | ||
const MS_DAY = 24 * 60 * 60 * 1000; | ||
|
||
const SecurityRecommendations: React.FC<Props> = ({ devices }) => { | ||
const devicesArray = Object.values(devices); | ||
|
||
const unverifiedDevicesCount = filterDevicesBySecurityRecommendation( | ||
devicesArray, | ||
[DeviceSecurityVariation.Unverified], | ||
).length; | ||
const inactiveDevicesCount = filterDevicesBySecurityRecommendation( | ||
devicesArray, | ||
[DeviceSecurityVariation.Inactive], | ||
).length; | ||
|
||
if (!(unverifiedDevicesCount | inactiveDevicesCount)) { | ||
return null; | ||
} | ||
|
||
const inactiveAgeDays = INACTIVE_DEVICE_AGE_MS / MS_DAY; | ||
|
||
// TODO(kerrya) stubbed until PSG-640/652 | ||
const noop = () => {}; | ||
|
||
return <SettingsSubsection | ||
heading={_t('Security recommendations')} | ||
description={_t('Improve your account security by following these recommendations')} | ||
data-testid='security-recommendations-section' | ||
> | ||
{ | ||
!!unverifiedDevicesCount && | ||
<DeviceSecurityCard | ||
variation={DeviceSecurityVariation.Unverified} | ||
heading={_t('Unverified sessions')} | ||
description={_t( | ||
`Verify your sessions for enhanced secure messaging` + | ||
` or sign out from those you don't recognize or use anymore.`, | ||
)} | ||
> | ||
<AccessibleButton | ||
kind='link_inline' | ||
onClick={noop} | ||
> | ||
{ _t('View all') + ` (${unverifiedDevicesCount})` } | ||
</AccessibleButton> | ||
</DeviceSecurityCard> | ||
} | ||
{ | ||
!!inactiveDevicesCount && | ||
<> | ||
{ !!unverifiedDevicesCount && <div className='mx_SecurityRecommendations_spacing' /> } | ||
<DeviceSecurityCard | ||
variation={DeviceSecurityVariation.Inactive} | ||
heading={_t('Inactive sessions')} | ||
description={_t( | ||
`Consider signing out from old sessions ` + | ||
`(%(inactiveAgeDays)s days or older) you don't use anymore`, | ||
{ inactiveAgeDays }, | ||
)} | ||
> | ||
<AccessibleButton | ||
kind='link_inline' | ||
onClick={noop} | ||
> | ||
{ _t('View all') + ` (${inactiveDevicesCount})` } | ||
</AccessibleButton> | ||
</DeviceSecurityCard> | ||
</> | ||
} | ||
</SettingsSubsection>; | ||
}; | ||
|
||
export default SecurityRecommendations; |
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
Copyright 2022 The Matrix.org Foundation C.I.C. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
import { IMyDevice } from "matrix-js-sdk/src/matrix"; | ||
|
||
export type DeviceWithVerification = IMyDevice & { isVerified: boolean | null }; | ||
export type DevicesDictionary = Record<DeviceWithVerification['device_id'], DeviceWithVerification>; | ||
|
||
export enum DeviceSecurityVariation { | ||
Verified = 'Verified', | ||
Unverified = 'Unverified', | ||
Inactive = 'Inactive', | ||
} |
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
72 changes: 72 additions & 0 deletions
72
test/components/views/settings/devices/SecurityRecommendations-test.tsx
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,72 @@ | ||
/* | ||
Copyright 2022 The Matrix.org Foundation C.I.C. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
|
||
import SecurityRecommendations from '../../../../../src/components/views/settings/devices/SecurityRecommendations'; | ||
|
||
const MS_DAY = 24 * 60 * 60 * 1000; | ||
describe('<SecurityRecommendations />', () => { | ||
const unverifiedNoMetadata = { device_id: 'unverified-no-metadata', isVerified: false }; | ||
const verifiedNoMetadata = { device_id: 'verified-no-metadata', isVerified: true }; | ||
const hundredDaysOld = { device_id: '100-days-old', isVerified: true, last_seen_ts: Date.now() - (MS_DAY * 100) }; | ||
const hundredDaysOldUnverified = { | ||
device_id: 'unverified-100-days-old', | ||
isVerified: false, | ||
last_seen_ts: Date.now() - (MS_DAY * 100), | ||
}; | ||
|
||
const defaultProps = { | ||
devices: {}, | ||
}; | ||
const getComponent = (props = {}) => | ||
(<SecurityRecommendations {...defaultProps} {...props} />); | ||
|
||
it('renders null when no devices', () => { | ||
const { container } = render(getComponent()); | ||
expect(container.firstChild).toBeNull(); | ||
}); | ||
|
||
it('renders unverified devices section when user has unverified devices', () => { | ||
const devices = { | ||
[unverifiedNoMetadata.device_id]: unverifiedNoMetadata, | ||
[verifiedNoMetadata.device_id]: verifiedNoMetadata, | ||
[hundredDaysOldUnverified.device_id]: hundredDaysOldUnverified, | ||
}; | ||
const { container } = render(getComponent({ devices })); | ||
expect(container).toMatchSnapshot(); | ||
}); | ||
|
||
it('renders inactive devices section when user has inactive devices', () => { | ||
const devices = { | ||
[verifiedNoMetadata.device_id]: verifiedNoMetadata, | ||
[hundredDaysOldUnverified.device_id]: hundredDaysOldUnverified, | ||
}; | ||
const { container } = render(getComponent({ devices })); | ||
expect(container).toMatchSnapshot(); | ||
}); | ||
|
||
it('renders both cards when user has both unverified and inactive devices', () => { | ||
const devices = { | ||
[verifiedNoMetadata.device_id]: verifiedNoMetadata, | ||
[hundredDaysOld.device_id]: hundredDaysOld, | ||
[unverifiedNoMetadata.device_id]: unverifiedNoMetadata, | ||
}; | ||
const { container } = render(getComponent({ devices })); | ||
expect(container).toMatchSnapshot(); | ||
}); | ||
}); |
Oops, something went wrong.