keycloak-service
公開メンバ関数 | 静的公開メンバ関数 | 変数 | 静的変数 | 非公開メンバ関数 | 静的非公開メンバ関数 | 全メンバ一覧
org.keycloak.procotol.docker.installation.DockerComposeYamlInstallationProviderTest クラス
org.keycloak.procotol.docker.installation.DockerComposeYamlInstallationProviderTest 連携図
Collaboration graph

公開メンバ関数

void setUp ()
 
void writeToRealZip () throws IOException
 
void testAllTheZipThings () throws Exception
 
void shouldIncludeDockerComposeYamlInZip (ZipInputStream zipInput) throws Exception
 
void shouldIncludeReadmeInZip (ZipInputStream zipInput) throws Exception
 
void shouldWriteBlankDataDirectoryInZip (ZipInputStream zipInput) throws Exception
 
void shouldWriteCertDirectoryInZip (ZipInputStream zipInput) throws Exception
 
void shouldWriteSslCertificateInZip (ZipInputStream zipInput) throws Exception
 
void shouldWritePrivateKeyInZip (ZipInputStream zipInput) throws Exception
 

静的公開メンバ関数

static void setUp_beforeClass () throws NoSuchAlgorithmException
 

変数

DockerComposeYamlInstallationProvider installationProvider
 

静的変数

static Certificate certificate
 

非公開メンバ関数

Response fireInstallationProvider () throws IOException
 
ZipInputStream getZipResponseFromInstallProvider (Response response) throws IOException
 

静的非公開メンバ関数

static Optional< String > getFileContents (final ZipInputStream zipInputStream, final String fileName) throws IOException
 
static String readBytesToString (final InputStream inputStream) throws IOException
 

詳解

関数詳解

◆ fireInstallationProvider()

Response org.keycloak.procotol.docker.installation.DockerComposeYamlInstallationProviderTest.fireInstallationProvider ( ) throws IOException
inlineprivate
61  {
62  ByteArrayOutputStream byteStream = null;
63  ZipOutputStream zipOutput = null;
64  byteStream = new ByteArrayOutputStream();
65  zipOutput = new ZipOutputStream(byteStream);
66 
67  return installationProvider.generateInstallation(zipOutput, byteStream, certificate, new URL("http://localhost:8080/auth"), "docker-test", "docker-registry");
68  }
static Certificate certificate
Definition: DockerComposeYamlInstallationProviderTest.java:44
DockerComposeYamlInstallationProvider installationProvider
Definition: DockerComposeYamlInstallationProviderTest.java:43
Response generateInstallation(final KeycloakSession session, final RealmModel realm, final ClientModel client, final URI serverBaseUri)
Definition: DockerComposeYamlInstallationProvider.java:56

◆ getFileContents()

static Optional<String> org.keycloak.procotol.docker.installation.DockerComposeYamlInstallationProviderTest.getFileContents ( final ZipInputStream  zipInputStream,
final String  fileName 
) throws IOException
inlinestaticprivate
170  {
171  ZipEntry zipEntry;
172  while ((zipEntry = zipInputStream.getNextEntry()) != null) {
173  try {
174  if (zipEntry.getName().equals(fileName)) {
175  return Optional.of(readBytesToString(zipInputStream));
176  }
177  } finally {
178  zipInputStream.closeEntry();
179  }
180  }
181 
182  // fall-through case if file name not found:
183  return Optional.empty();
184  }
static String readBytesToString(final InputStream inputStream)
Definition: DockerComposeYamlInstallationProviderTest.java:186

◆ getZipResponseFromInstallProvider()

ZipInputStream org.keycloak.procotol.docker.installation.DockerComposeYamlInstallationProviderTest.getZipResponseFromInstallProvider ( Response  response) throws IOException
inlineprivate
161  {
162  final Object responseEntity = response.getEntity();
163  if (!(responseEntity instanceof byte[])) {
164  fail("Recieved non-byte[] entity for docker-compose YAML installation response");
165  }
166 
167  return new ZipInputStream(new ByteArrayInputStream((byte[]) responseEntity));
168  }

◆ readBytesToString()

static String org.keycloak.procotol.docker.installation.DockerComposeYamlInstallationProviderTest.readBytesToString ( final InputStream  inputStream) throws IOException
inlinestaticprivate
186  {
187  final ByteArrayOutputStream output = new ByteArrayOutputStream();
188  final byte[] buffer = new byte[4096];
189  int bytesRead;
190 
191  try {
192  while ((bytesRead = inputStream.read(buffer)) != -1) {
193  output.write(buffer, 0, bytesRead);
194  }
195  } finally {
196  output.close();
197  }
198 
199  return new String(output.toByteArray());
200  }

◆ setUp()

void org.keycloak.procotol.docker.installation.DockerComposeYamlInstallationProviderTest.setUp ( )
inline
57  {
58  installationProvider = new DockerComposeYamlInstallationProvider();
59  }
DockerComposeYamlInstallationProvider installationProvider
Definition: DockerComposeYamlInstallationProviderTest.java:43

◆ setUp_beforeClass()

static void org.keycloak.procotol.docker.installation.DockerComposeYamlInstallationProviderTest.setUp_beforeClass ( ) throws NoSuchAlgorithmException
inlinestatic
47  {
48  final KeyPairGenerator keyGen;
49  keyGen = KeyPairGenerator.getInstance("RSA");
50  keyGen.initialize(2048, new SecureRandom());
51 
52  final KeyPair keypair = keyGen.generateKeyPair();
53  certificate = CertificateUtils.generateV1SelfSignedCertificate(keypair, "test-realm");
54  }
static Certificate certificate
Definition: DockerComposeYamlInstallationProviderTest.java:44

◆ shouldIncludeDockerComposeYamlInZip()

void org.keycloak.procotol.docker.installation.DockerComposeYamlInstallationProviderTest.shouldIncludeDockerComposeYamlInZip ( ZipInputStream  zipInput) throws Exception
inline
91  {
92  final Optional<String> actualDockerComposeFileContents = getFileContents(zipInput, ROOT_DIR + "docker-compose.yaml");
93 
94  assertThat("Could not find docker-compose.yaml file in zip archive response", actualDockerComposeFileContents.isPresent(), equalTo(true));
95 
96  List<String> expectedDockerComposeAsStringLines = FileUtils.readLines(new File("src/test/resources/docker-compose-expected.yaml"), Charset.defaultCharset());
97  String[] actualDockerComposeAsStringLines = actualDockerComposeFileContents.get().split("\n");
98 
99  String messageIfTestFails = "Invalid docker-compose file contents: \n" + actualDockerComposeFileContents.get();
100  for (int i = 0; i < expectedDockerComposeAsStringLines.size(); i++) {
101  assertEquals(messageIfTestFails, expectedDockerComposeAsStringLines.get(i), actualDockerComposeAsStringLines[i]);
102  }
103  }
static Optional< String > getFileContents(final ZipInputStream zipInputStream, final String fileName)
Definition: DockerComposeYamlInstallationProviderTest.java:170

◆ shouldIncludeReadmeInZip()

void org.keycloak.procotol.docker.installation.DockerComposeYamlInstallationProviderTest.shouldIncludeReadmeInZip ( ZipInputStream  zipInput) throws Exception
inline
105  {
106  final Optional<String> dockerComposeFileContents = getFileContents(zipInput, ROOT_DIR + "README.md");
107 
108  assertThat("Could not find README.md file in zip archive response", dockerComposeFileContents.isPresent(), equalTo(true));
109  }
static Optional< String > getFileContents(final ZipInputStream zipInputStream, final String fileName)
Definition: DockerComposeYamlInstallationProviderTest.java:170

◆ shouldWriteBlankDataDirectoryInZip()

void org.keycloak.procotol.docker.installation.DockerComposeYamlInstallationProviderTest.shouldWriteBlankDataDirectoryInZip ( ZipInputStream  zipInput) throws Exception
inline
111  {
112  ZipEntry zipEntry;
113  boolean dataDirFound = false;
114  while ((zipEntry = zipInput.getNextEntry()) != null) {
115  try {
116  if (zipEntry.getName().equals(ROOT_DIR + "data/")) {
117  dataDirFound = true;
118  assertThat("Zip entry for data directory is not the correct type", zipEntry.isDirectory(), equalTo(true));
119  }
120  } finally {
121  zipInput.closeEntry();
122  }
123  }
124 
125  assertThat("Could not find data directory", dataDirFound, equalTo(true));
126  }

◆ shouldWriteCertDirectoryInZip()

void org.keycloak.procotol.docker.installation.DockerComposeYamlInstallationProviderTest.shouldWriteCertDirectoryInZip ( ZipInputStream  zipInput) throws Exception
inline
128  {
129  ZipEntry zipEntry;
130  boolean certsDirFound = false;
131  while ((zipEntry = zipInput.getNextEntry()) != null) {
132  try {
133  if (zipEntry.getName().equals(ROOT_DIR + "certs/")) {
134  certsDirFound = true;
135  assertThat("Zip entry for cert directory is not the correct type", zipEntry.isDirectory(), equalTo(true));
136  }
137  } finally {
138  zipInput.closeEntry();
139  }
140  }
141 
142  assertThat("Could not find cert directory", certsDirFound, equalTo(true));
143  }

◆ shouldWritePrivateKeyInZip()

void org.keycloak.procotol.docker.installation.DockerComposeYamlInstallationProviderTest.shouldWritePrivateKeyInZip ( ZipInputStream  zipInput) throws Exception
inline
153  {
154  final Optional<String> localhostPrivateKeyFileContents = getFileContents(zipInput, ROOT_DIR + "certs/localhost.key");
155 
156  assertThat("Could not find localhost private key", localhostPrivateKeyFileContents.isPresent(), equalTo(true));
157  final PrivateKey privateKey = PemUtils.decodePrivateKey(localhostPrivateKeyFileContents.get());
158  assertThat("Invalid private Key given by docker-compose YAML", privateKey, notNullValue());
159  }
static Optional< String > getFileContents(final ZipInputStream zipInputStream, final String fileName)
Definition: DockerComposeYamlInstallationProviderTest.java:170

◆ shouldWriteSslCertificateInZip()

void org.keycloak.procotol.docker.installation.DockerComposeYamlInstallationProviderTest.shouldWriteSslCertificateInZip ( ZipInputStream  zipInput) throws Exception
inline
145  {
146  final Optional<String> localhostCertificateFileContents = getFileContents(zipInput, ROOT_DIR + "certs/localhost.crt");
147 
148  assertThat("Could not find localhost certificate", localhostCertificateFileContents.isPresent(), equalTo(true));
149  final X509Certificate x509Certificate = PemUtils.decodeCertificate(localhostCertificateFileContents.get());
150  assertThat("Invalid x509 given by docker-compose YAML", x509Certificate, notNullValue());
151  }
static Optional< String > getFileContents(final ZipInputStream zipInputStream, final String fileName)
Definition: DockerComposeYamlInstallationProviderTest.java:170

◆ testAllTheZipThings()

void org.keycloak.procotol.docker.installation.DockerComposeYamlInstallationProviderTest.testAllTheZipThings ( ) throws Exception
inline
79  {
80  final Response response = fireInstallationProvider();
81  assertThat("compose YAML returned non-ok response", response.getStatus(), equalTo(Response.Status.OK.getStatusCode()));
82 
89  }
void shouldIncludeDockerComposeYamlInZip(ZipInputStream zipInput)
Definition: DockerComposeYamlInstallationProviderTest.java:91
void shouldIncludeReadmeInZip(ZipInputStream zipInput)
Definition: DockerComposeYamlInstallationProviderTest.java:105
void shouldWriteCertDirectoryInZip(ZipInputStream zipInput)
Definition: DockerComposeYamlInstallationProviderTest.java:128
void shouldWritePrivateKeyInZip(ZipInputStream zipInput)
Definition: DockerComposeYamlInstallationProviderTest.java:153
void shouldWriteSslCertificateInZip(ZipInputStream zipInput)
Definition: DockerComposeYamlInstallationProviderTest.java:145
ZipInputStream getZipResponseFromInstallProvider(Response response)
Definition: DockerComposeYamlInstallationProviderTest.java:161
Response fireInstallationProvider()
Definition: DockerComposeYamlInstallationProviderTest.java:61
void shouldWriteBlankDataDirectoryInZip(ZipInputStream zipInput)
Definition: DockerComposeYamlInstallationProviderTest.java:111

◆ writeToRealZip()

void org.keycloak.procotol.docker.installation.DockerComposeYamlInstallationProviderTest.writeToRealZip ( ) throws IOException
inline
72  {
73  final Response response = fireInstallationProvider();
74  final byte[] responseBytes = (byte[]) response.getEntity();
75  FileUtils.writeByteArrayToFile(new File("target/keycloak-docker-compose-yaml.zip"), responseBytes);
76  }
Response fireInstallationProvider()
Definition: DockerComposeYamlInstallationProviderTest.java:61

メンバ詳解

◆ certificate

Certificate org.keycloak.procotol.docker.installation.DockerComposeYamlInstallationProviderTest.certificate
staticpackage

◆ installationProvider

DockerComposeYamlInstallationProvider org.keycloak.procotol.docker.installation.DockerComposeYamlInstallationProviderTest.installationProvider
package

このクラス詳解は次のファイルから抽出されました: