This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6724 from matrix-org/rav/log_saml_attributes
* commit '59dc87c61': changelog Log saml assertions rather than the whole response move batch_iter to a separate module
- Loading branch information
Showing
11 changed files
with
114 additions
and
24 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
When processing a SAML response, log the assertions for easier configuration. |
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2014-2016 OpenMarket Ltd | ||
# Copyright 2020 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. | ||
from itertools import islice | ||
from typing import Iterable, Iterator, Sequence, Tuple, TypeVar | ||
|
||
T = TypeVar("T") | ||
|
||
|
||
def batch_iter(iterable: Iterable[T], size: int) -> Iterator[Tuple[T]]: | ||
"""batch an iterable up into tuples with a maximum size | ||
Args: | ||
iterable (iterable): the iterable to slice | ||
size (int): the maximum batch size | ||
Returns: | ||
an iterator over the chunks | ||
""" | ||
# make sure we can deal with iterables like lists too | ||
sourceiter = iter(iterable) | ||
# call islice until it returns an empty tuple | ||
return iter(lambda: tuple(islice(sourceiter, size)), ()) | ||
|
||
|
||
ISeq = TypeVar("ISeq", bound=Sequence, covariant=True) | ||
|
||
|
||
def chunk_seq(iseq: ISeq, maxlen: int) -> Iterable[ISeq]: | ||
"""Split the given sequence into chunks of the given size | ||
The last chunk may be shorter than the given size. | ||
If the input is empty, no chunks are returned. | ||
""" | ||
return (iseq[i : i + maxlen] for i in range(0, len(iseq), maxlen)) |
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,47 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2020 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. | ||
from synapse.util.iterutils import chunk_seq | ||
|
||
from tests.unittest import TestCase | ||
|
||
|
||
class ChunkSeqTests(TestCase): | ||
def test_short_seq(self): | ||
parts = chunk_seq("123", 8) | ||
|
||
self.assertEqual( | ||
list(parts), ["123"], | ||
) | ||
|
||
def test_long_seq(self): | ||
parts = chunk_seq("abcdefghijklmnop", 8) | ||
|
||
self.assertEqual( | ||
list(parts), ["abcdefgh", "ijklmnop"], | ||
) | ||
|
||
def test_uneven_parts(self): | ||
parts = chunk_seq("abcdefghijklmnop", 5) | ||
|
||
self.assertEqual( | ||
list(parts), ["abcde", "fghij", "klmno", "p"], | ||
) | ||
|
||
def test_empty_input(self): | ||
parts = chunk_seq([], 5) | ||
|
||
self.assertEqual( | ||
list(parts), [], | ||
) |