aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.ssh.apache.test/tst/org/eclipse/jgit/internal/signing/ssh/SshSignerTest.java
blob: b3a4482d23d814d723e8fb7e6b9e2d7abdc45af6 (plain)
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
/*
 * Copyright (C) 2024, Thomas Wolf <twolf@apache.org> and others
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Distribution License v. 1.0 which is available at
 * https://www.eclipse.org/org/documents/edl-v10.php.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */
package org.eclipse.jgit.internal.signing.ssh;

import static org.junit.Assert.assertThrows;
import static org.junit.Assert.fail;

import org.junit.Test;

/**
 * Tests for the {@link SshSigner}.
 */
public class SshSignerTest extends AbstractSshSignatureTest {

	@Test
	public void testPlainSignature() throws Exception {
		checkSshSignature(createSignedCommit(null, "signing_key.pub"));
	}

	@Test
	public void testExpiredSignature() throws Exception {
		Throwable t = assertThrows(Throwable.class,
				() -> createSignedCommit("expired.cert",
						"signing_key-cert.pub"));
		// The exception or one of its causes should mention "[Ee]xpired" and
		// "[Cc]ertificate" in the message
		while (t != null) {
			String message = t.getMessage();
			if (message.contains("xpired") && message.contains("ertificate")) {
				return;
			}
			t = t.getCause();
		}
		fail("Expected exception message not found");
	}

	@Test
	public void testCertificateSignature() throws Exception {
		checkSshSignature(createSignedCommit("tester.cert", "signing_key.pub"));
	}

	@Test
	public void testNoPrincipalsSignature() throws Exception {
		// Certificate has no principals; should still work
		checkSshSignature(
				createSignedCommit("no_principals.cert", "signing_key.pub"));
	}

	@Test
	public void testOtherSignature() throws Exception {
		// Certificate has a principal different that tester@example.com; should
		// still work
		checkSshSignature(createSignedCommit("other.cert", "signing_key.pub"));
	}
}