-
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.
Signed-off-by: Milton Moura <[email protected]>
- Loading branch information
Showing
18 changed files
with
775 additions
and
2 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
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 |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Copyright 2024 Nordeck IT + Consulting GmbH | ||
* | ||
* 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 { describe, expect, it } from 'vitest'; | ||
import { isValidRoomEncryptionEvent } from './roomEncryptionEvent'; | ||
|
||
describe('is valid event', () => { | ||
it('should accept event', () => { | ||
expect( | ||
isValidRoomEncryptionEvent({ | ||
content: { | ||
algorithm: 'm.megolm.v1.aes-sha2', | ||
}, | ||
event_id: '$event-id', | ||
origin_server_ts: 0, | ||
room_id: '!room-id', | ||
state_key: '', | ||
sender: '@user-id', | ||
type: 'm.room.encryption', | ||
}), | ||
).toBe(true); | ||
}); | ||
|
||
it('should accept additional properties', () => { | ||
expect( | ||
isValidRoomEncryptionEvent({ | ||
content: { | ||
algorithm: 'm.megolm.v1.aes-sha2', | ||
rotation_period_ms: 604800000, | ||
rotation_period_msgs: 100, | ||
}, | ||
event_id: '$event-id', | ||
origin_server_ts: 0, | ||
room_id: '!room-id', | ||
state_key: '', | ||
sender: '@user-id', | ||
type: 'm.room.encryption', | ||
}), | ||
).toBe(true); | ||
}); | ||
|
||
it.each<object>([{ algorithm: undefined }, { algorithm: null }])( | ||
'should reject event with patch %j', | ||
(patch: object) => { | ||
expect( | ||
isValidRoomEncryptionEvent({ | ||
content: { | ||
algorithm: 'm.megolm.v1.aes-sha2', | ||
...patch, | ||
}, | ||
event_id: '$event-id', | ||
origin_server_ts: 0, | ||
room_id: '!room-id', | ||
state_key: '', | ||
sender: '@user-id', | ||
type: 'm.room.encryption', | ||
}), | ||
).toBe(false); | ||
}, | ||
); | ||
}); |
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,40 @@ | ||
/* | ||
* Copyright 2024 Nordeck IT + Consulting GmbH | ||
* | ||
* 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 { StateEvent } from '@matrix-widget-toolkit/api'; | ||
import Joi from 'joi'; | ||
import { isValidEvent } from './validation'; | ||
|
||
export const STATE_EVENT_ROOM_ENCRYPTION = 'm.room.encryption'; | ||
|
||
export type RoomEncryptionEvent = { | ||
algorithm: string; | ||
}; | ||
|
||
// based on https://github.com/matrix-org/matrix-spec/blob/03cdea4b57320926a6da73ad3b3f6c7f4fd0a7c2/data/event-schemas/schema/m.room.encryption.yaml | ||
const roomEncryptionEventSchema = Joi.object<RoomEncryptionEvent, true>({ | ||
algorithm: Joi.string().required(), | ||
}).unknown(); | ||
|
||
export function isValidRoomEncryptionEvent( | ||
event: StateEvent<unknown>, | ||
): event is StateEvent<RoomEncryptionEvent> { | ||
return isValidEvent( | ||
event, | ||
STATE_EVENT_ROOM_ENCRYPTION, | ||
roomEncryptionEventSchema, | ||
); | ||
} |
77 changes: 77 additions & 0 deletions
77
packages/react-sdk/src/model/roomHistoryVisibilityEvent.test.ts
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,77 @@ | ||
/* | ||
* Copyright 2024 Nordeck IT + Consulting GmbH | ||
* | ||
* 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 { describe, expect, it } from 'vitest'; | ||
import { isValidRoomHistoryVisibilityEvent } from './roomHistoryVisibilityEvent'; | ||
|
||
describe('is valid event', () => { | ||
it('should accept event', () => { | ||
expect( | ||
isValidRoomHistoryVisibilityEvent({ | ||
content: { | ||
history_visibility: 'shared', | ||
}, | ||
event_id: '$event-id', | ||
origin_server_ts: 0, | ||
room_id: '!room-id', | ||
state_key: '', | ||
sender: '@user-id', | ||
type: 'm.room.history_visibility', | ||
}), | ||
).toBe(true); | ||
}); | ||
|
||
it.each<object>([ | ||
{ history_visibility: 'invited' }, | ||
{ history_visibility: 'joined' }, | ||
{ history_visibility: 'world_readable' }, | ||
])('should accept event with patch %j', (patch: object) => { | ||
expect( | ||
isValidRoomHistoryVisibilityEvent({ | ||
content: { | ||
history_visibility: 'shared', | ||
...patch, | ||
}, | ||
event_id: '$event-id', | ||
origin_server_ts: 0, | ||
room_id: '!room-id', | ||
state_key: '', | ||
sender: '@user-id', | ||
type: 'm.room.history_visibility', | ||
}), | ||
).toBe(true); | ||
}); | ||
|
||
it.each<object>([ | ||
{ history_visibility: undefined }, | ||
{ history_visibility: null }, | ||
])('should reject event with patch %j', (patch: object) => { | ||
expect( | ||
isValidRoomHistoryVisibilityEvent({ | ||
content: { | ||
history_visibility: 'shared', | ||
...patch, | ||
}, | ||
event_id: '$event-id', | ||
origin_server_ts: 0, | ||
room_id: '!room-id', | ||
state_key: '', | ||
sender: '@user-id', | ||
type: 'm.room.history_visibility', | ||
}), | ||
).toBe(false); | ||
}); | ||
}); |
43 changes: 43 additions & 0 deletions
43
packages/react-sdk/src/model/roomHistoryVisibilityEvent.ts
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,43 @@ | ||
/* | ||
* Copyright 2024 Nordeck IT + Consulting GmbH | ||
* | ||
* 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 { StateEvent } from '@matrix-widget-toolkit/api'; | ||
import Joi from 'joi'; | ||
import { isValidEvent } from './validation'; | ||
|
||
export const STATE_EVENT_ROOM_HISTORY_VISIBILITY = 'm.room.history_visibility'; | ||
|
||
export type RoomHistoryVisibilityEvent = { | ||
history_visibility: string; | ||
}; | ||
|
||
// based on https://github.com/matrix-org/matrix-spec/blob/03cdea4b57320926a6da73ad3b3f6c7f4fd0a7c2/data/event-schemas/schema/m.room.history_visibility.yaml | ||
const roomHistoryVisibilityEventSchema = Joi.object< | ||
RoomHistoryVisibilityEvent, | ||
true | ||
>({ | ||
history_visibility: Joi.string().required(), | ||
}).unknown(); | ||
|
||
export function isValidRoomHistoryVisibilityEvent( | ||
event: StateEvent<unknown>, | ||
): event is StateEvent<RoomHistoryVisibilityEvent> { | ||
return isValidEvent( | ||
event, | ||
STATE_EVENT_ROOM_HISTORY_VISIBILITY, | ||
roomHistoryVisibilityEventSchema, | ||
); | ||
} |
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
Oops, something went wrong.