|
1 | 1 | #!/bin/bash
|
2 | 2 |
|
3 |
| -echo "=== Test 1: uploading and downloading a text file without encryption ===" |
4 |
| -TMPFILE="test.txt.tmp" |
5 |
| -mxc_key=$(matrix-commander --upload tests/test.txt --plain) |
6 |
| -echo "$mxc_key" # has the URI, like "mxc://... None" |
7 |
| -mxc="${mxc_key% *}" # before " " |
8 |
| -key="${mxc_key##* }" # after " " |
9 |
| -echo "mxc is \"$mxc\"" |
10 |
| -echo "key is \"$key\"" # None in our case, because plain-text |
11 |
| -rm -f "$TMPFILE" |
12 |
| -# download knows it is plain because we do not specify a key dictionary |
13 |
| -matrix-commander --download "$mxc" --file-name "$TMPFILE" |
14 |
| -diff "$TMPFILE" "tests/test.txt" |
15 |
| -res="$?" |
16 |
| -if [ "$res" == "0" ]; then |
17 |
| - echo "SUCCESS" |
18 |
| - echo "Let's look at the text." |
19 |
| - cat "$TMPFILE" # look at the image |
20 |
| -else |
21 |
| - echo "FAILURE" |
22 |
| -fi |
23 |
| - |
24 |
| -echo "=== Test 2: uploading and downloading an image file with encryption ===" |
25 |
| -mxc_key=$(matrix-commander --upload tests/test.s.png) |
26 |
| -echo "$mxc_key" # has the URI, like "mxc://... {some key dictionary}" |
27 |
| -mxc="${mxc_key% *}" # before " " |
28 |
| -key="${mxc_key##* }" # after " " |
29 |
| -echo "mxc is \"$mxc\"" |
30 |
| -echo "key is \"$key\"" |
31 |
| -rm -f "$TMPFILE" |
32 |
| -# download knows it is encrypted because we specify a key dictionary |
33 |
| -matrix-commander --download "$mxc" --file-name "$TMPFILE" --key-dict "$key" |
34 |
| -diff "$TMPFILE" "tests/test.s.png" |
35 |
| -res="$?" |
36 |
| -if [ "$res" == "0" ]; then |
37 |
| - echo "SUCCESS" |
38 |
| - type eog >/dev/null 2>&1 && { |
| 3 | +# just in case PATH is not set correctly |
| 4 | +PATH=".:./matrix_commander:../matrix_commander:$PATH" |
| 5 | + |
| 6 | +function test1() { |
| 7 | + echo "=== Test 1: uploading and downloading a text file without encryption ===" |
| 8 | + TMPFILE="test.txt.tmp" |
| 9 | + mxc_key=$(matrix-commander --upload tests/test.txt --plain) |
| 10 | + echo "$mxc_key" # has the URI, like "mxc://... None" |
| 11 | + mxc="${mxc_key% *}" # before " " |
| 12 | + key="${mxc_key##* }" # after " " |
| 13 | + echo "mxc is \"$mxc\"" |
| 14 | + echo "key is \"$key\"" # None in our case, because plain-text |
| 15 | + rm -f "$TMPFILE" |
| 16 | + # download knows it is plain because we do not specify a key dictionary |
| 17 | + matrix-commander --download "$mxc" --file-name "$TMPFILE" |
| 18 | + diff "$TMPFILE" "tests/test.txt" |
| 19 | + res="$?" |
| 20 | + if [ "$res" == "0" ]; then |
| 21 | + echo "SUCCESS" |
| 22 | + echo "Let's look at the text." |
| 23 | + cat "$TMPFILE" # look at the text file |
| 24 | + else |
| 25 | + echo "FAILURE" |
| 26 | + fi |
| 27 | +} |
| 28 | + |
| 29 | +function test2() { |
| 30 | + echo "=== Test 2: uploading and downloading an image file with encryption ===" |
| 31 | + mxc_key=$(matrix-commander --upload tests/test.s.png) |
| 32 | + echo "$mxc_key" # has the URI, like "mxc://... {some key dictionary}" |
| 33 | + mxc="${mxc_key% *}" # before " " |
| 34 | + key="${mxc_key##* }" # after " " |
| 35 | + echo "mxc is \"$mxc\"" |
| 36 | + echo "key is \"$key\"" |
| 37 | + rm -f "$TMPFILE" |
| 38 | + # download knows it is encrypted because we specify a key dictionary |
| 39 | + matrix-commander --download "$mxc" --file-name "$TMPFILE" --key-dict "$key" |
| 40 | + diff "$TMPFILE" "tests/test.s.png" |
| 41 | + res="$?" |
| 42 | + if [ "$res" == "0" ]; then |
| 43 | + echo "SUCCESS" |
| 44 | + type eog >/dev/null 2>&1 && { |
| 45 | + echo "Let's look at the image." |
| 46 | + eog "$TMPFILE" >/dev/null 2>&1 |
| 47 | + } |
| 48 | + else |
| 49 | + echo "FAILURE" |
| 50 | + fi |
| 51 | + rm -f "$TMPFILE" |
| 52 | +} |
| 53 | + |
| 54 | +function test3() { |
| 55 | + echo "=== Test 3: uploading and downloading 2 text files without encryption ===" |
| 56 | + N=2 # 2 files to test |
| 57 | + TESTFILES=("tests/test.1.txt" "tests/test.2.txt") |
| 58 | + TMPFILES=("test.1.txt.tmp" "test.2.txt.tmp") |
| 59 | + rm -f "${TMPFILES[@]}" |
| 60 | + mxc_keys=$(matrix-commander --upload ${TESTFILES[0]} ${TESTFILES[1]} --plain) |
| 61 | + echo "$mxc_keys" # has the N URIs, like "mxc://... None" |
| 62 | + MXCS=() |
| 63 | + KEYS=() |
| 64 | + for ii in $(seq $N); do |
| 65 | + echo "Handling file $ii" |
| 66 | + mxc_key=$(echo "$mxc_keys" | head -n $ii | tail -n 1) |
| 67 | + mxc="${mxc_key% *}" # before " " |
| 68 | + key="${mxc_key##* }" # after " " |
| 69 | + echo "mxc is \"$mxc\"" |
| 70 | + echo "key is \"$key\"" # None in our case, because plain-text |
| 71 | + MXCS+=("$mxc") # append mxc to array |
| 72 | + KEYS+=("$key") # append mxc to array |
| 73 | + done |
| 74 | + rm -f "${TMPFILES[0]}" "${TMPFILES[1]}" |
| 75 | + # download knows it is plain because we do not specify a key dictionary |
| 76 | + matrix-commander --download "${MXCS[0]}" "${MXCS[1]}" \ |
| 77 | + --file-name "${TMPFILES[0]}" "${TMPFILES[1]}" |
| 78 | + for ii in $(seq $N); do |
| 79 | + ((ii = ii - 1)) |
| 80 | + diff "${TMPFILES[$ii]}" "${TESTFILES[$ii]}" |
| 81 | + res="$?" |
| 82 | + if [ "$res" == "0" ]; then |
| 83 | + echo "SUCCESS" |
| 84 | + echo "Let's look at the text." |
| 85 | + cat "${TMPFILES[$ii]}" # look at the text file |
| 86 | + else |
| 87 | + echo "FAILURE" |
| 88 | + fi |
| 89 | + rm "${TMPFILES[$ii]}" |
| 90 | + done |
| 91 | +} |
| 92 | + |
| 93 | +function test4() { |
| 94 | + echo "=== Test 4: convert MXC to HTTP URL ===" |
| 95 | + TMPFILE="test.txt.tmp" |
| 96 | + rm -f "$TMPFILE" |
| 97 | + mxc_http=$(matrix-commander --mxc-to-http "${MXCS[0]}") |
| 98 | + echo "$mxc_http" # has the URI and the URL |
| 99 | + mxc="${mxc_http% *}" # before " " |
| 100 | + http="${mxc_http##* }" # after " " |
| 101 | + echo "mxc is \"$mxc\"" |
| 102 | + echo "mxc_http is \"$http\"" |
| 103 | + wget -O "$TMPFILE" "$http" |
| 104 | + diff "$TMPFILE" "tests/test.1.txt" |
| 105 | + res="$?" |
| 106 | + if [ "$res" == "0" ]; then |
| 107 | + echo "SUCCESS" |
39 | 108 | echo "Let's look at the image."
|
40 |
| - eog "$TMPFILE" >/dev/null 2>&1 |
41 |
| - } |
42 |
| -else |
43 |
| - echo "FAILURE" |
44 |
| -fi |
45 |
| -rm -f "$TMPFILE" |
| 109 | + cat "$TMPFILE" # look at the text file |
| 110 | + else |
| 111 | + echo "FAILURE" |
| 112 | + fi |
| 113 | + rm -f "$TMPFILE" |
| 114 | + |
| 115 | +} |
| 116 | + |
| 117 | +function test5() { |
| 118 | + echo "=== Test 5: uploading and downloading 2 text files with encryption ===" |
| 119 | + N=2 # 2 files to test |
| 120 | + TESTFILES=("tests/test.1.txt" "tests/test.2.txt") |
| 121 | + TMPFILES=("test.1.txt.tmp" "test.2.txt.tmp") |
| 122 | + rm -f "${TMPFILES[@]}" |
| 123 | + mxc_keys=$(matrix-commander --upload ${TESTFILES[0]} ${TESTFILES[1]}) |
| 124 | + echo "$mxc_keys" # has the N URIs, like "mxc://... None" |
| 125 | + MXCS=() |
| 126 | + KEYS=() |
| 127 | + for ii in $(seq $N); do |
| 128 | + echo "Handling file $ii" |
| 129 | + mxc_key=$(echo "$mxc_keys" | head -n $ii | tail -n 1) |
| 130 | + mxc="${mxc_key% *}" # before " " |
| 131 | + key="${mxc_key##* }" # after " " |
| 132 | + echo "mxc is \"$mxc\"" |
| 133 | + echo "key is \"$key\"" # a key dict |
| 134 | + MXCS+=("$mxc") # append mxc to array |
| 135 | + KEYS+=("$key") # append mxc to array |
| 136 | + done |
| 137 | + rm -f "${TMPFILES[0]}" "${TMPFILES[1]}" |
| 138 | + # download knows it is encrypted because we do specify a key dictionary |
| 139 | + matrix-commander --download "${MXCS[0]}" "${MXCS[1]}" \ |
| 140 | + --file-name "${TMPFILES[0]}" "${TMPFILES[1]}" \ |
| 141 | + --key-dict "${KEYS[0]}" "${KEYS[1]}" |
| 142 | + for ii in $(seq $N); do |
| 143 | + ((ii = ii - 1)) |
| 144 | + diff "${TMPFILES[$ii]}" "${TESTFILES[$ii]}" |
| 145 | + res="$?" |
| 146 | + if [ "$res" == "0" ]; then |
| 147 | + echo "SUCCESS" |
| 148 | + echo "Let's look at the text." |
| 149 | + cat "${TMPFILES[$ii]}" # look at the text file |
| 150 | + else |
| 151 | + echo "FAILURE" |
| 152 | + fi |
| 153 | + rm "${TMPFILES[$ii]}" |
| 154 | + done |
| 155 | +} |
| 156 | + |
| 157 | +function test6() { |
| 158 | + echo "=== Test 6: deleting MXC resources from content repository ===" |
| 159 | + echo "Note: This will FAIL if you do not have server admin permissions!" |
| 160 | + matrix-commander --delete-mxc "${MXCS[0]}" "${MXCS[1]}" |
| 161 | +} |
| 162 | + |
| 163 | +test1 |
| 164 | +test2 |
| 165 | +test3 |
| 166 | +test4 |
| 167 | +test5 |
| 168 | +test6 |
0 commit comments