sapling/eden/mononoke/tests/integration/test-lfs-server-rate-limiting.t
Doug Neal 1e088c0af2 mononoke: lfs_server: add optional client identities to ratelimit config
Summary:
* Added intermediate (de)serializers for config types, so that we generate full Identity objects at config load time
* Implement FromStr for Identity
* Compare configured identities to presented identities in ratelimit middleware in order to decide whether or not to apply the limit

Reviewed By: krallin

Differential Revision: D20139308

fbshipit-source-id: 340c300db549575eb6d06efcbe437c0b1db4927b
2020-03-03 09:33:03 -08:00

52 lines
1.6 KiB
Raku

# Copyright (c) Facebook, Inc. and its affiliates.
#
# This software may be used and distributed according to the terms of the
# GNU General Public License found in the LICENSE file in the root
# directory of this source tree.
$ . "${TEST_FIXTURES}/library.sh"
# Create a repository
$ setup_mononoke_config
$ REPOID=1 setup_mononoke_repo_config repo1
$ LIVE_CONFIG="${TESTTMP}/live.json"
$ cat > "$LIVE_CONFIG" << EOF
> {
> "track_bytes_sent": true,
> "enable_consistent_routing": false,
> "disable_hostname_logging": false,
> "throttle_limits": [
> {
> "counter": "mononoke.lfs.download.size_bytes_sent.sum.5",
> "limit": 10,
> "sleep_ms": 1000,
> "max_jitter_ms": 100,
> "client_identities": [
> "USER:myusername0"
> ]
> }
> ],
> "acl_check": true,
> "enforce_acl_check": false
> }
> EOF
# Start an LFS server
$ lfs_log="$TESTTMP/lfs.log"
$ lfs_uri="$(lfs_server --tls --log "$lfs_log" --live-config "file:${LIVE_CONFIG}")/repo1"
# Upload data
$ yes A 2>/dev/null | head -c 2KiB | ssldebuglfssend "$lfs_uri"
ab02c2a1923c8eb11cb3ddab70320746d71d32ad63f255698dc67c3295757746 2048
# Download the file. Note the blake2 is used here.
$ sslcurl -s -o /dev/null -w "%{http_code}\n" "${lfs_uri}/download/d28548bc21aabf04d143886d717d72375e3deecd0dafb3d110676b70a192cb5d"
200
# Give stats aggregation time to complete
$ sleep 2
# Next request should be throttled
$ sslcurl -s -o /dev/null -w "%{http_code}\n" "${lfs_uri}/download/d28548bc21aabf04d143886d717d72375e3deecd0dafb3d110676b70a192cb5d"
429