forked from 8go/matrix-commander
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-upload.sh
executable file
·175 lines (165 loc) · 5.82 KB
/
test-upload.sh
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#!/bin/bash
# just in case PATH is not set correctly
PATH=".:./matrix_commander:../matrix_commander:$PATH"
function test1() {
echo "=== Test 1: uploading and downloading a text file without encryption ==="
TMPFILE="test.txt.tmp"
mxc_key=$(matrix-commander --upload tests/test.txt --plain)
echo "$mxc_key" # has the URI, like "mxc://... None"
mxc="${mxc_key% *}" # before " "
key="${mxc_key##* }" # after " "
echo "mxc is \"$mxc\""
echo "key is \"$key\"" # None in our case, because plain-text
rm -f "$TMPFILE"
# download knows it is plain because we do not specify a key dictionary
matrix-commander --download "$mxc" --file-name "$TMPFILE"
diff "$TMPFILE" "tests/test.txt"
res="$?"
if [ "$res" == "0" ]; then
echo "SUCCESS"
echo "Let's look at the text."
cat "$TMPFILE" # look at the text file
else
echo "FAILURE"
fi
}
function test2() {
echo "=== Test 2: uploading and downloading an image file with encryption ==="
mxc_key=$(matrix-commander --upload tests/test.s.png)
echo "$mxc_key" # has the URI, like "mxc://... {some key dictionary}"
mxc="${mxc_key% *}" # before " "
key="${mxc_key##* }" # after " "
echo "mxc is \"$mxc\""
echo "key is \"$key\""
rm -f "$TMPFILE"
# download knows it is encrypted because we specify a key dictionary
matrix-commander --download "$mxc" --file-name "$TMPFILE" --key-dict "$key"
diff "$TMPFILE" "tests/test.s.png"
res="$?"
if [ "$res" == "0" ]; then
echo "SUCCESS"
type eog >/dev/null 2>&1 && {
echo "Let's look at the image."
eog "$TMPFILE" >/dev/null 2>&1
}
else
echo "FAILURE"
fi
rm -f "$TMPFILE"
}
function test3() {
echo "=== Test 3: uploading and downloading 2 text files without encryption ==="
N=2 # 2 files to test
TESTFILES=("tests/test.1.txt" "tests/test.2.txt")
TMPFILES=("test.1.txt.tmp" "test.2.txt.tmp")
rm -f "${TMPFILES[@]}"
mxc_keys=$(matrix-commander --upload ${TESTFILES[0]} ${TESTFILES[1]} --plain)
echo "$mxc_keys" # has the N URIs, like "mxc://... None"
MXCS=()
KEYS=()
for ii in $(seq $N); do
echo "Handling file $ii"
mxc_key=$(echo "$mxc_keys" | head -n $ii | tail -n 1)
mxc="${mxc_key% *}" # before " "
key="${mxc_key##* }" # after " "
echo "mxc is \"$mxc\""
echo "key is \"$key\"" # None in our case, because plain-text
MXCS+=("$mxc") # append mxc to array
KEYS+=("$key") # append mxc to array
done
rm -f "${TMPFILES[0]}" "${TMPFILES[1]}"
# download knows it is plain because we do not specify a key dictionary
matrix-commander --download "${MXCS[0]}" "${MXCS[1]}" \
--file-name "${TMPFILES[0]}" "${TMPFILES[1]}"
for ii in $(seq $N); do
((ii = ii - 1))
diff "${TMPFILES[$ii]}" "${TESTFILES[$ii]}"
res="$?"
if [ "$res" == "0" ]; then
echo "SUCCESS"
echo "Let's look at the text."
cat "${TMPFILES[$ii]}" # look at the text file
else
echo "FAILURE"
fi
rm "${TMPFILES[$ii]}"
done
}
function test4() {
echo "=== Test 4: convert MXC to HTTP URL ==="
TMPFILE="test.txt.tmp"
rm -f "$TMPFILE"
mxc_http=$(matrix-commander --mxc-to-http "${MXCS[0]}")
echo "$mxc_http" # has the URI and the URL
mxc="${mxc_http% *}" # before " "
http="${mxc_http##* }" # after " "
echo "mxc is \"$mxc\""
echo "mxc_http is \"$http\""
wget -O "$TMPFILE" "$http"
diff "$TMPFILE" "tests/test.1.txt"
res="$?"
if [ "$res" == "0" ]; then
echo "SUCCESS"
echo "Let's look at the text file."
cat "$TMPFILE" # look at the text file
else
echo "FAILURE"
fi
rm -f "$TMPFILE"
}
function test5() {
echo "=== Test 5: uploading and downloading 2 text files with encryption ==="
N=2 # 2 files to test
TESTFILES=("tests/test.1.txt" "tests/test.2.txt")
TMPFILES=("test.1.txt.tmp" "test.2.txt.tmp")
rm -f "${TMPFILES[@]}"
mxc_keys=$(matrix-commander --upload ${TESTFILES[0]} ${TESTFILES[1]})
echo "$mxc_keys" # has the N URIs, like "mxc://... None"
MXCS=()
KEYS=()
for ii in $(seq $N); do
echo "Handling file $ii"
mxc_key=$(echo "$mxc_keys" | head -n $ii | tail -n 1)
mxc="${mxc_key% *}" # before " "
key="${mxc_key##* }" # after " "
echo "mxc is \"$mxc\""
echo "key is \"$key\"" # a key dict
MXCS+=("$mxc") # append mxc to array
KEYS+=("$key") # append mxc to array
done
rm -f "${TMPFILES[0]}" "${TMPFILES[1]}"
# download knows it is encrypted because we do specify a key dictionary
matrix-commander --download "${MXCS[0]}" "${MXCS[1]}" \
--file-name "${TMPFILES[0]}" "${TMPFILES[1]}" \
--key-dict "${KEYS[0]}" "${KEYS[1]}"
for ii in $(seq $N); do
((ii = ii - 1))
diff "${TMPFILES[$ii]}" "${TESTFILES[$ii]}"
res="$?"
if [ "$res" == "0" ]; then
echo "SUCCESS"
echo "Let's look at the text."
cat "${TMPFILES[$ii]}" # look at the text file
else
echo "FAILURE"
fi
rm "${TMPFILES[$ii]}"
done
}
function test6() {
echo "=== Test 6: deleting MXC resources from content repository ==="
echo "Note: This will FAIL if you do not have server admin permissions!"
matrix-commander --delete-mxc "${MXCS[0]}" "${MXCS[1]}"
}
function test7() {
echo "=== Test 7: deleting old resources from content repository ==="
echo "Note: This will FAIL if you do not have server admin permissions!"
matrix-commander --delete-mxc-before "20.01.2022 19:38:42" "1000000"
}
test1
test2
test3
test4
test5
test6
test7