|
| 1 | +#!/usr/bin/env bash |
| 2 | +# |
| 3 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 4 | +# or more contributor license agreements. See the NOTICE file |
| 5 | +# distributed with this work for additional information |
| 6 | +# regarding copyright ownership. The ASF licenses this file |
| 7 | +# to you under the Apache License, Version 2.0 (the |
| 8 | +# "License"); you may not use this file except in compliance |
| 9 | +# with the License. You may obtain a copy of the License at |
| 10 | +# |
| 11 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +# |
| 13 | +# Unless required by applicable law or agreed to in writing, |
| 14 | +# software distributed under the License is distributed on an |
| 15 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 16 | +# KIND, either express or implied. See the License for the |
| 17 | +# specific language governing permissions and limitations |
| 18 | +# under the License. |
| 19 | +# |
| 20 | + |
| 21 | +set -e -x |
| 22 | + |
| 23 | +export PULSAR_EXTRA_OPTS=-Dpulsar.auth.basic.conf=test-conf/.htpasswd |
| 24 | + |
| 25 | +# Generate secret key and token |
| 26 | +mkdir -p data/tokens |
| 27 | +bin/pulsar tokens create-secret-key --output data/tokens/secret.key |
| 28 | + |
| 29 | +bin/pulsar tokens create \ |
| 30 | + --subject token-principal \ |
| 31 | + --secret-key file:///pulsar/data/tokens/secret.key \ |
| 32 | + > /pulsar/data/tokens/token.txt |
| 33 | + |
| 34 | +export PULSAR_STANDALONE_CONF=test-conf/standalone-ssl.conf |
| 35 | +export PULSAR_PID_DIR=/tmp |
| 36 | +bin/pulsar-daemon start standalone \ |
| 37 | + --no-functions-worker --no-stream-storage \ |
| 38 | + --bookkeeper-dir data/bookkeeper |
| 39 | + |
| 40 | +echo "-- Wait for Pulsar service to be ready" |
| 41 | +until curl http://localhost:8080/metrics > /dev/null 2>&1 ; do sleep 1; done |
| 42 | + |
| 43 | +echo "-- Pulsar service is ready -- Configure permissions" |
| 44 | + |
| 45 | +export PULSAR_CLIENT_CONF=test-conf/client-ssl.conf |
| 46 | + |
| 47 | +# Create "standalone" cluster if it does not exist |
| 48 | +bin/pulsar-admin clusters list | grep -q '^standalone$' || |
| 49 | + bin/pulsar-admin clusters create \ |
| 50 | + standalone \ |
| 51 | + --url http://localhost:8080/ \ |
| 52 | + --url-secure https://localhost:8443/ \ |
| 53 | + --broker-url pulsar://localhost:6650/ \ |
| 54 | + --broker-url-secure pulsar+ssl://localhost:6651/ |
| 55 | + |
| 56 | +# Update "public" tenant |
| 57 | +bin/pulsar-admin tenants create public -r "anonymous" -c "standalone" |
| 58 | + |
| 59 | +# Update "public/default" with no auth required |
| 60 | +bin/pulsar-admin namespaces create public/default -c standalone |
| 61 | +bin/pulsar-admin namespaces grant-permission public/default \ |
| 62 | + --actions produce,consume \ |
| 63 | + --role "anonymous" |
| 64 | + |
| 65 | +# Create "public/default-2" with no auth required |
| 66 | +bin/pulsar-admin namespaces create public/default-2 \ |
| 67 | + --clusters standalone |
| 68 | +bin/pulsar-admin namespaces grant-permission public/default-2 \ |
| 69 | + --actions produce,consume \ |
| 70 | + --role "anonymous" |
| 71 | + |
| 72 | +# Create "public/default-3" with no auth required |
| 73 | +bin/pulsar-admin namespaces create public/default-3 \ |
| 74 | + --clusters standalone |
| 75 | +bin/pulsar-admin namespaces grant-permission public/default-3 \ |
| 76 | + --actions produce,consume \ |
| 77 | + --role "anonymous" |
| 78 | + |
| 79 | +# Create "public/default-4" with encryption required |
| 80 | +bin/pulsar-admin namespaces create public/default-4 \ |
| 81 | + --clusters standalone |
| 82 | +bin/pulsar-admin namespaces grant-permission public/default-4 \ |
| 83 | + --actions produce,consume \ |
| 84 | + --role "anonymous" |
| 85 | +bin/pulsar-admin namespaces set-encryption-required public/default-4 -e |
| 86 | + |
| 87 | +# Create "public/test-backlog-quotas" to test backlog quotas policy |
| 88 | +bin/pulsar-admin namespaces create public/test-backlog-quotas \ |
| 89 | + --clusters standalone |
| 90 | + |
| 91 | +# Create "private" tenant |
| 92 | +bin/pulsar-admin tenants create private -r "" -c "standalone" |
| 93 | + |
| 94 | +# Create "private/auth" with required authentication |
| 95 | +bin/pulsar-admin namespaces create private/auth --clusters standalone |
| 96 | + |
| 97 | +bin/pulsar-admin namespaces grant-permission private/auth \ |
| 98 | + --actions produce,consume \ |
| 99 | + --role "token-principal" |
| 100 | + |
| 101 | +echo "-- Ready to start tests" |
0 commit comments