|
| 1 | +// Copyright (c) inlets Author(s) 2019. All rights reserved. |
| 2 | +// Licensed under the MIT license. See LICENSE file in the project root for full license information. |
| 3 | + |
| 4 | +package main |
| 5 | + |
| 6 | +import ( |
| 7 | + "testing" |
| 8 | +) |
| 9 | + |
| 10 | +func Test_MakeUserdata_InletsPro(t *testing.T) { |
| 11 | + userData := MakeExitServerUserdata("auth", "0.7.0", "") |
| 12 | + |
| 13 | + wantUserdata := `#!/bin/bash |
| 14 | +export AUTHTOKEN="auth" |
| 15 | +export IP=$(curl -sfSL https://checkip.amazonaws.com) |
| 16 | +export PROXY_PROTO="" |
| 17 | +
|
| 18 | +curl -SLsf https://github.com/inlets/inlets-pro/releases/download/0.7.0/inlets-pro -o /tmp/inlets-pro && \ |
| 19 | + chmod +x /tmp/inlets-pro && \ |
| 20 | + mv /tmp/inlets-pro /usr/local/bin/inlets-pro |
| 21 | +
|
| 22 | +cat > /etc/systemd/system/inlets-pro.service <<EOF |
| 23 | +[Unit] |
| 24 | +Description=inlets TCP server |
| 25 | +After=network.target |
| 26 | +
|
| 27 | +[Service] |
| 28 | +Type=simple |
| 29 | +Restart=always |
| 30 | +RestartSec=2 |
| 31 | +StartLimitInterval=0 |
| 32 | +EnvironmentFile=/etc/default/inlets-pro |
| 33 | +ExecStart=/usr/local/bin/inlets-pro tcp server --auto-tls --auto-tls-san="\${IP}" --token="\${AUTHTOKEN}" --proxy-protocol="\${PROXY_PROTO}" |
| 34 | +
|
| 35 | +[Install] |
| 36 | +WantedBy=multi-user.target |
| 37 | +EOF |
| 38 | +
|
| 39 | +echo "AUTHTOKEN=$AUTHTOKEN" >> /etc/default/inlets-pro && \ |
| 40 | + echo "IP=$IP" >> /etc/default/inlets-pro && \ |
| 41 | + echo "PROXY_PROTO=$PROXY_PROTO" >> /etc/default/inlets-pro && \ |
| 42 | + systemctl daemon-reload && \ |
| 43 | + systemctl start inlets-pro && \ |
| 44 | + systemctl enable inlets-pro |
| 45 | +` |
| 46 | + |
| 47 | + if userData != wantUserdata { |
| 48 | + t.Errorf("want: %s, but got: %s", wantUserdata, userData) |
| 49 | + } |
| 50 | +} |
| 51 | + |
| 52 | +func Test_MakeUserdata_InletsPro_WithProxyProto(t *testing.T) { |
| 53 | + userData := MakeExitServerUserdata("auth", "0.7.0", "v1") |
| 54 | + |
| 55 | + wantUserdata := `#!/bin/bash |
| 56 | +export AUTHTOKEN="auth" |
| 57 | +export IP=$(curl -sfSL https://checkip.amazonaws.com) |
| 58 | +export PROXY_PROTO="v1" |
| 59 | +
|
| 60 | +curl -SLsf https://github.com/inlets/inlets-pro/releases/download/0.7.0/inlets-pro -o /tmp/inlets-pro && \ |
| 61 | + chmod +x /tmp/inlets-pro && \ |
| 62 | + mv /tmp/inlets-pro /usr/local/bin/inlets-pro |
| 63 | +
|
| 64 | +cat > /etc/systemd/system/inlets-pro.service <<EOF |
| 65 | +[Unit] |
| 66 | +Description=inlets TCP server |
| 67 | +After=network.target |
| 68 | +
|
| 69 | +[Service] |
| 70 | +Type=simple |
| 71 | +Restart=always |
| 72 | +RestartSec=2 |
| 73 | +StartLimitInterval=0 |
| 74 | +EnvironmentFile=/etc/default/inlets-pro |
| 75 | +ExecStart=/usr/local/bin/inlets-pro tcp server --auto-tls --auto-tls-san="\${IP}" --token="\${AUTHTOKEN}" --proxy-protocol="\${PROXY_PROTO}" |
| 76 | +
|
| 77 | +[Install] |
| 78 | +WantedBy=multi-user.target |
| 79 | +EOF |
| 80 | +
|
| 81 | +echo "AUTHTOKEN=$AUTHTOKEN" >> /etc/default/inlets-pro && \ |
| 82 | + echo "IP=$IP" >> /etc/default/inlets-pro && \ |
| 83 | + echo "PROXY_PROTO=$PROXY_PROTO" >> /etc/default/inlets-pro && \ |
| 84 | + systemctl daemon-reload && \ |
| 85 | + systemctl start inlets-pro && \ |
| 86 | + systemctl enable inlets-pro |
| 87 | +` |
| 88 | + |
| 89 | + if userData != wantUserdata { |
| 90 | + t.Errorf("want: %s, but got: %s", wantUserdata, userData) |
| 91 | + } |
| 92 | +} |
0 commit comments