forked from docker-java/docker-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAuthConfigFileTest.java
More file actions
115 lines (90 loc) · 3.92 KB
/
Copy pathAuthConfigFileTest.java
File metadata and controls
115 lines (90 loc) · 3.92 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/**
* Copyright (C) 2014 SignalFuse, Inc.
*/
package com.github.dockerjava.core;
import java.io.File;
import java.io.IOException;
import org.testng.Assert;
import org.testng.annotations.Test;
import com.github.dockerjava.api.model.AuthConfig;
public class AuthConfigFileTest {
private final File FILESROOT = new File(Thread.currentThread().getContextClassLoader()
.getResource("testAuthConfigFile").getFile());
@Test(expectedExceptions = IOException.class, expectedExceptionsMessageRegExp = "The Auth Config file is empty")
public void emptyFile() throws IOException {
runTest("emptyFile");
}
@Test(expectedExceptions = IOException.class, expectedExceptionsMessageRegExp = "The Auth Config file is empty")
public void tooSmallFile() throws IOException {
runTest("tooSmallFile");
}
@Test(expectedExceptions = IOException.class, expectedExceptionsMessageRegExp = "Invalid auth configuration file")
public void invalidJsonInvalidAuth() throws IOException {
runTest("invalidJsonInvalidAuth");
}
@Test(expectedExceptions = IOException.class, expectedExceptionsMessageRegExp = "Invalid Auth config file")
public void invalidLegacyAuthLine() throws IOException {
runTest("invalidLegacyAuthLine");
}
@Test(expectedExceptions = IOException.class, expectedExceptionsMessageRegExp = "Invalid auth configuration file")
public void invalidLegacyInvalidAuth() throws IOException {
runTest("invalidLegacyInvalidAuth");
}
@Test(expectedExceptions = IOException.class, expectedExceptionsMessageRegExp = "Invalid Auth config file")
public void invalidLegacyEmailLine() throws IOException {
runTest("invalidLegacyEmailLine");
}
@Test
public void validJson() throws IOException {
AuthConfig authConfig1 = new AuthConfig()
.withEmail("foo@example.com")
.withUsername("foo")
.withPassword("bar")
.withRegistryAddress("quay.io");
AuthConfig authConfig2 = new AuthConfig()
.withEmail("moo@example.com")
.withUsername("foo1")
.withPassword("bar1")
.withRegistryAddress(AuthConfig.DEFAULT_SERVER_ADDRESS);
AuthConfigFile expected = new AuthConfigFile();
expected.addConfig(authConfig1);
expected.addConfig(authConfig2);
Assert.assertEquals(runTest("validJson.json"), expected);
}
@Test
public void validJsonWithUnknown() throws IOException {
AuthConfig authConfig1 = new AuthConfig()
.withEmail("foo@example.com")
.withUsername("foo")
.withPassword("bar")
.withRegistryAddress("quay.io");
AuthConfigFile expected = new AuthConfigFile();
expected.addConfig(authConfig1);
runTest("validJsonWithUnknown.json");
}
@Test
public void validJsonWithOnlyUnknown() throws IOException {
AuthConfigFile expected = new AuthConfigFile();
AuthConfigFile actual = runTest("validJsonWithOnlyUnknown.json");
Assert.assertEquals(actual, expected);
}
@Test
public void validLegacy() throws IOException {
AuthConfig authConfig = new AuthConfig()
.withEmail("foo@example.com")
.withUsername("foo")
.withPassword("bar")
.withRegistryAddress(AuthConfig.DEFAULT_SERVER_ADDRESS);
AuthConfigFile expected = new AuthConfigFile();
expected.addConfig(authConfig);
Assert.assertEquals(runTest("validLegacy"), expected);
}
@Test
public void nonExistent() throws IOException {
AuthConfigFile expected = new AuthConfigFile();
Assert.assertEquals(runTest("idontexist"), expected);
}
private AuthConfigFile runTest(String testFileName) throws IOException {
return AuthConfigFile.loadConfig(new File(FILESROOT, testFileName));
}
}