| 1 |
use assert_cmd::Command; |
| 2 |
use predicates::prelude::*; |
| 3 |
use std::path; |
| 4 |
|
| 5 |
/// Verifies a detached signature. |
| 6 |
#[test] |
| 7 |
fn detached() { |
| 8 |
Command::cargo_bin("sqv").expect("have sqv") |
| 9 |
.current_dir(path::Path::new("tests").join("data")) |
| 10 |
.args(&[ |
| 11 |
"--keyring", |
| 12 |
"emmelie-dorothea-dina-samantha-awina-ed25519.pgp", |
| 13 |
"--signature-file=a-cypherpunks-manifesto.txt.ed25519.sig", |
| 14 |
"a-cypherpunks-manifesto.txt", |
| 15 |
]) |
| 16 |
.assert() |
| 17 |
.success() |
| 18 |
.stdout(predicate::eq( |
| 19 |
b"8E8C33FA4626337976D97978069C0C348DD82C19\n" as &[u8])); |
| 20 |
|
| 21 |
// Conflicts with --output. |
| 22 |
Command::cargo_bin("sqv").expect("have sqv") |
| 23 |
.current_dir(path::Path::new("tests").join("data")) |
| 24 |
.args(&[ |
| 25 |
"--keyring", |
| 26 |
"emmelie-dorothea-dina-samantha-awina-ed25519.pgp", |
| 27 |
"--output=authenticated.txt", |
| 28 |
"--signature-file=a-cypherpunks-manifesto.txt.ed25519.sig", |
| 29 |
"a-cypherpunks-manifesto.txt", |
| 30 |
]) |
| 31 |
.assert() |
| 32 |
.failure(); |
| 33 |
|
| 34 |
// Read the signature from stdin. |
| 35 |
Command::cargo_bin("sqv").expect("have sqv") |
| 36 |
.current_dir(path::Path::new("tests").join("data")) |
| 37 |
.pipe_stdin("tests/data/a-cypherpunks-manifesto.txt.ed25519.sig").expect("can read file") |
| 38 |
.args(&[ |
| 39 |
"--keyring", |
| 40 |
"emmelie-dorothea-dina-samantha-awina-ed25519.pgp", |
| 41 |
"--signature-file=-", |
| 42 |
"a-cypherpunks-manifesto.txt", |
| 43 |
]) |
| 44 |
.assert() |
| 45 |
.success() |
| 46 |
.stdout(predicate::eq( |
| 47 |
b"8E8C33FA4626337976D97978069C0C348DD82C19\n" as &[u8])); |
| 48 |
|
| 49 |
// Read the data from stdin. |
| 50 |
Command::cargo_bin("sqv").expect("have sqv") |
| 51 |
.current_dir(path::Path::new("tests").join("data")) |
| 52 |
.pipe_stdin("tests/data/a-cypherpunks-manifesto.txt").expect("can read file") |
| 53 |
.args(&[ |
| 54 |
"--keyring", |
| 55 |
"emmelie-dorothea-dina-samantha-awina-ed25519.pgp", |
| 56 |
"--signature-file=a-cypherpunks-manifesto.txt.ed25519.sig", |
| 57 |
"-", |
| 58 |
]) |
| 59 |
.assert() |
| 60 |
.success() |
| 61 |
.stdout(predicate::eq( |
| 62 |
b"8E8C33FA4626337976D97978069C0C348DD82C19\n" as &[u8])); |
| 63 |
|
| 64 |
// Read the keyring from stdin. |
| 65 |
Command::cargo_bin("sqv").expect("have sqv") |
| 66 |
.current_dir(path::Path::new("tests").join("data")) |
| 67 |
.pipe_stdin("tests/data/emmelie-dorothea-dina-samantha-awina-ed25519.pgp").expect("can read file") |
| 68 |
.args(&[ |
| 69 |
"--keyring", |
| 70 |
"-", |
| 71 |
"--signature-file=a-cypherpunks-manifesto.txt.ed25519.sig", |
| 72 |
"a-cypherpunks-manifesto.txt", |
| 73 |
]) |
| 74 |
.assert() |
| 75 |
.success() |
| 76 |
.stdout(predicate::eq( |
| 77 |
b"8E8C33FA4626337976D97978069C0C348DD82C19\n" as &[u8])); |
| 78 |
} |
| 79 |
|
| 80 |
/// Verifies a detached signature using the legacy form. |
| 81 |
#[test] |
| 82 |
fn detached_legacy() { |
| 83 |
Command::cargo_bin("sqv").expect("have sqv") |
| 84 |
.current_dir(path::Path::new("tests").join("data")) |
| 85 |
.args(&[ |
| 86 |
"--keyring", |
| 87 |
"emmelie-dorothea-dina-samantha-awina-ed25519.pgp", |
| 88 |
"a-cypherpunks-manifesto.txt.ed25519.sig", |
| 89 |
"a-cypherpunks-manifesto.txt", |
| 90 |
]) |
| 91 |
.assert() |
| 92 |
.success() |
| 93 |
.stdout(predicate::eq( |
| 94 |
b"8E8C33FA4626337976D97978069C0C348DD82C19\n" as &[u8])); |
| 95 |
|
| 96 |
// Read the signature from stdin. |
| 97 |
Command::cargo_bin("sqv").expect("have sqv") |
| 98 |
.current_dir(path::Path::new("tests").join("data")) |
| 99 |
.pipe_stdin("tests/data/a-cypherpunks-manifesto.txt.ed25519.sig").expect("can read file") |
| 100 |
.args(&[ |
| 101 |
"--keyring", |
| 102 |
"emmelie-dorothea-dina-samantha-awina-ed25519.pgp", |
| 103 |
"-", |
| 104 |
"a-cypherpunks-manifesto.txt", |
| 105 |
]) |
| 106 |
.assert() |
| 107 |
.success() |
| 108 |
.stdout(predicate::eq( |
| 109 |
b"8E8C33FA4626337976D97978069C0C348DD82C19\n" as &[u8])); |
| 110 |
|
| 111 |
// Read the data from stdin. |
| 112 |
Command::cargo_bin("sqv").expect("have sqv") |
| 113 |
.current_dir(path::Path::new("tests").join("data")) |
| 114 |
.pipe_stdin("tests/data/a-cypherpunks-manifesto.txt").expect("can read file") |
| 115 |
.args(&[ |
| 116 |
"--keyring", |
| 117 |
"emmelie-dorothea-dina-samantha-awina-ed25519.pgp", |
| 118 |
"a-cypherpunks-manifesto.txt.ed25519.sig", |
| 119 |
"-", |
| 120 |
]) |
| 121 |
.assert() |
| 122 |
.success() |
| 123 |
.stdout(predicate::eq( |
| 124 |
b"8E8C33FA4626337976D97978069C0C348DD82C19\n" as &[u8])); |
| 125 |
|
| 126 |
// Read the keyring from stdin. |
| 127 |
Command::cargo_bin("sqv").expect("have sqv") |
| 128 |
.current_dir(path::Path::new("tests").join("data")) |
| 129 |
.pipe_stdin("tests/data/emmelie-dorothea-dina-samantha-awina-ed25519.pgp").expect("can read file") |
| 130 |
.args(&[ |
| 131 |
"--keyring", |
| 132 |
"-", |
| 133 |
"a-cypherpunks-manifesto.txt.ed25519.sig", |
| 134 |
"a-cypherpunks-manifesto.txt", |
| 135 |
]) |
| 136 |
.assert() |
| 137 |
.success() |
| 138 |
.stdout(predicate::eq( |
| 139 |
b"8E8C33FA4626337976D97978069C0C348DD82C19\n" as &[u8])); |
| 140 |
} |
| 141 |
|
| 142 |
/// Verifies an inline-signed message. |
| 143 |
#[test] |
| 144 |
fn inline_signed_message() { |
| 145 |
let p = tempfile::tempdir().unwrap(); |
| 146 |
let auth = p.path().join("authenticated.txt").display().to_string(); |
| 147 |
|
| 148 |
Command::cargo_bin("sqv").expect("have sqv") |
| 149 |
.current_dir(path::Path::new("tests").join("data")) |
| 150 |
.args(&[ |
| 151 |
"--keyring", |
| 152 |
"emmelie-dorothea-dina-samantha-awina-ed25519.pgp", |
| 153 |
"--output", &auth, |
| 154 |
"--message", |
| 155 |
"a-cypherpunks-manifesto.pgp", |
| 156 |
]) |
| 157 |
.assert() |
| 158 |
.success() |
| 159 |
.stdout(predicate::eq( |
| 160 |
b"8E8C33FA4626337976D97978069C0C348DD82C19\n" as &[u8])); |
| 161 |
|
| 162 |
let reference = path::Path::new("tests").join("data") |
| 163 |
.join("a-cypherpunks-manifesto.txt"); |
| 164 |
assert_eq!(std::fs::read(&auth).unwrap(), |
| 165 |
std::fs::read(&reference).unwrap()); |
| 166 |
|
| 167 |
// Requires --output. |
| 168 |
Command::cargo_bin("sqv").expect("have sqv") |
| 169 |
.current_dir(path::Path::new("tests").join("data")) |
| 170 |
.args(&[ |
| 171 |
"--keyring", |
| 172 |
"emmelie-dorothea-dina-samantha-awina-ed25519.pgp", |
| 173 |
"--message", |
| 174 |
"a-cypherpunks-manifesto.pgp", |
| 175 |
]) |
| 176 |
.assert() |
| 177 |
.failure(); |
| 178 |
|
| 179 |
// Read the message from stdin. |
| 180 |
Command::cargo_bin("sqv").expect("have sqv") |
| 181 |
.current_dir(path::Path::new("tests").join("data")) |
| 182 |
.pipe_stdin("tests/data/a-cypherpunks-manifesto.pgp").expect("can read file") |
| 183 |
.args(&[ |
| 184 |
"--overwrite", |
| 185 |
"--keyring", |
| 186 |
"emmelie-dorothea-dina-samantha-awina-ed25519.pgp", |
| 187 |
"--output", &auth, |
| 188 |
"--message", |
| 189 |
"-", |
| 190 |
]) |
| 191 |
.assert() |
| 192 |
.success() |
| 193 |
.stdout(predicate::eq( |
| 194 |
b"8E8C33FA4626337976D97978069C0C348DD82C19\n" as &[u8])); |
| 195 |
|
| 196 |
|
| 197 |
// Read the keyring from stdin. |
| 198 |
Command::cargo_bin("sqv").expect("have sqv") |
| 199 |
.current_dir(path::Path::new("tests").join("data")) |
| 200 |
.pipe_stdin("tests/data/emmelie-dorothea-dina-samantha-awina-ed25519.pgp").expect("can read file") |
| 201 |
.args(&[ |
| 202 |
"--overwrite", |
| 203 |
"--keyring", |
| 204 |
"-", |
| 205 |
"--output", &auth, |
| 206 |
"--message", |
| 207 |
"a-cypherpunks-manifesto.pgp", |
| 208 |
]) |
| 209 |
.assert() |
| 210 |
.success() |
| 211 |
.stdout(predicate::eq( |
| 212 |
b"8E8C33FA4626337976D97978069C0C348DD82C19\n" as &[u8])); |
| 213 |
|
| 214 |
// Write to /dev/null without using --overwrite. |
| 215 |
Command::cargo_bin("sqv").expect("have sqv") |
| 216 |
.current_dir(path::Path::new("tests").join("data")) |
| 217 |
.args(&[ |
| 218 |
"--keyring", |
| 219 |
"emmelie-dorothea-dina-samantha-awina-ed25519.pgp", |
| 220 |
"--output", "/dev/null", |
| 221 |
"--message", |
| 222 |
"a-cypherpunks-manifesto.pgp", |
| 223 |
]) |
| 224 |
.assert() |
| 225 |
.success() |
| 226 |
.stdout(predicate::eq( |
| 227 |
b"8E8C33FA4626337976D97978069C0C348DD82C19\n" as &[u8])); |
| 228 |
} |
| 229 |
|
| 230 |
/// Verifies an cleartext-signed message. |
| 231 |
#[test] |
| 232 |
fn cleartext_signed_message() { |
| 233 |
let p = tempfile::tempdir().unwrap(); |
| 234 |
let auth = p.path().join("authenticated.txt").display().to_string(); |
| 235 |
|
| 236 |
Command::cargo_bin("sqv").expect("have sqv") |
| 237 |
.current_dir(path::Path::new("tests").join("data")) |
| 238 |
.args(&[ |
| 239 |
"--keyring", |
| 240 |
"emmelie-dorothea-dina-samantha-awina-ed25519.pgp", |
| 241 |
"--output", &auth, |
| 242 |
"--cleartext", |
| 243 |
"a-cypherpunks-manifesto.csf", |
| 244 |
]) |
| 245 |
.assert() |
| 246 |
.success() |
| 247 |
.stdout(predicate::eq( |
| 248 |
b"8E8C33FA4626337976D97978069C0C348DD82C19\n" as &[u8])); |
| 249 |
|
| 250 |
// Read the message from stdin. |
| 251 |
Command::cargo_bin("sqv").expect("have sqv") |
| 252 |
.current_dir(path::Path::new("tests").join("data")) |
| 253 |
.pipe_stdin("tests/data/a-cypherpunks-manifesto.csf").expect("can read file") |
| 254 |
.args(&[ |
| 255 |
"--overwrite", |
| 256 |
"--keyring", |
| 257 |
"emmelie-dorothea-dina-samantha-awina-ed25519.pgp", |
| 258 |
"--output", &auth, |
| 259 |
"--cleartext", |
| 260 |
"-", |
| 261 |
]) |
| 262 |
.assert() |
| 263 |
.success() |
| 264 |
.stdout(predicate::eq( |
| 265 |
b"8E8C33FA4626337976D97978069C0C348DD82C19\n" as &[u8])); |
| 266 |
|
| 267 |
// Read the keyring from stdin. |
| 268 |
Command::cargo_bin("sqv").expect("have sqv") |
| 269 |
.current_dir(path::Path::new("tests").join("data")) |
| 270 |
.pipe_stdin("tests/data/emmelie-dorothea-dina-samantha-awina-ed25519.pgp").expect("can read file") |
| 271 |
.args(&[ |
| 272 |
"--overwrite", |
| 273 |
"--keyring", |
| 274 |
"-", |
| 275 |
"--output", &auth, |
| 276 |
"--cleartext", |
| 277 |
"a-cypherpunks-manifesto.csf", |
| 278 |
]) |
| 279 |
.assert() |
| 280 |
.success() |
| 281 |
.stdout(predicate::eq( |
| 282 |
b"8E8C33FA4626337976D97978069C0C348DD82C19\n" as &[u8])); |
| 283 |
|
| 284 |
let reference = path::Path::new("tests").join("data") |
| 285 |
.join("a-cypherpunks-manifesto.txt"); |
| 286 |
let auth = |
| 287 |
String::from_utf8(std::fs::read(&auth).unwrap()).unwrap(); |
| 288 |
let reference = |
| 289 |
String::from_utf8(std::fs::read(&reference).unwrap()).unwrap(); |
| 290 |
assert_eq!(auth.trim_end(), reference.trim_end()); |
| 291 |
|
| 292 |
// Requires --output. |
| 293 |
Command::cargo_bin("sqv").expect("have sqv") |
| 294 |
.current_dir(path::Path::new("tests").join("data")) |
| 295 |
.args(&[ |
| 296 |
"--keyring", |
| 297 |
"emmelie-dorothea-dina-samantha-awina-ed25519.pgp", |
| 298 |
"--cleartext", |
| 299 |
"a-cypherpunks-manifesto.csf", |
| 300 |
]) |
| 301 |
.assert() |
| 302 |
.failure(); |
| 303 |
} |
| 304 |
|
| 305 |
/// Verifies overwrite switch. |
| 306 |
#[test] |
| 307 |
fn overwrite() { |
| 308 |
let p = tempfile::tempdir().unwrap(); |
| 309 |
let auth = p.path().join("authenticated.txt").display().to_string(); |
| 310 |
|
| 311 |
// create an output file |
| 312 |
Command::cargo_bin("sqv").expect("have sqv") |
| 313 |
.current_dir(path::Path::new("tests").join("data")) |
| 314 |
.args(&[ |
| 315 |
"--keyring", |
| 316 |
"emmelie-dorothea-dina-samantha-awina-ed25519.pgp", |
| 317 |
"--output", &auth, |
| 318 |
"--cleartext", |
| 319 |
"a-cypherpunks-manifesto.csf", |
| 320 |
]) |
| 321 |
.assert() |
| 322 |
.success() |
| 323 |
.stdout(predicate::eq( |
| 324 |
b"8E8C33FA4626337976D97978069C0C348DD82C19\n" as &[u8])); |
| 325 |
|
| 326 |
// repeat procedure - this has to fail |
| 327 |
Command::cargo_bin("sqv").expect("have sqv") |
| 328 |
.current_dir(path::Path::new("tests").join("data")) |
| 329 |
.args(&[ |
| 330 |
"--keyring", |
| 331 |
"emmelie-dorothea-dina-samantha-awina-ed25519.pgp", |
| 332 |
"--output", &auth, |
| 333 |
"--cleartext", |
| 334 |
"a-cypherpunks-manifesto.csf", |
| 335 |
]) |
| 336 |
.assert() |
| 337 |
.failure(); |
| 338 |
|
| 339 |
// repeat again - this time with '--overwrite', this should succeed |
| 340 |
// like the first incarnation (eg: same output) |
| 341 |
Command::cargo_bin("sqv").expect("have sqv") |
| 342 |
.current_dir(path::Path::new("tests").join("data")) |
| 343 |
.args(&[ |
| 344 |
"--keyring", |
| 345 |
"emmelie-dorothea-dina-samantha-awina-ed25519.pgp", |
| 346 |
"--output", &auth, |
| 347 |
"--overwrite", |
| 348 |
"--cleartext", |
| 349 |
"a-cypherpunks-manifesto.csf", |
| 350 |
]) |
| 351 |
.assert() |
| 352 |
.success() |
| 353 |
.stdout(predicate::eq( |
| 354 |
b"8E8C33FA4626337976D97978069C0C348DD82C19\n" as &[u8])); |
| 355 |
} |