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