Skip to content

Commit

Permalink
chore: linter updates
Browse files Browse the repository at this point in the history
Running the linter on the modified files

Signed-off-by: Dale Lane <[email protected]>
  • Loading branch information
dalelane committed Mar 7, 2024
1 parent f0a5613 commit 66a4538
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 62 deletions.
4 changes: 2 additions & 2 deletions components/Common.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,9 @@ export function EnvJson({ asyncapi, params }) {
const server = asyncapi.allServers().get(params.server);

if (
protocol === 'ibmmq-secure' &&
protocol === 'ibmmq-secure' &&
server.bindings().get('ibmmq').value().cipherSpec
) {
) {
cipher = MQCipherToJava(server.bindings().get('ibmmq').value().cipherSpec);
}

Expand Down
84 changes: 42 additions & 42 deletions components/Connection/MQTLS.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
export function MQCipherToJava(cipher) {
// List in line with Oracle JRE mappings from https://ibm.biz/mq-cipher-mappings
const ciphers = {
ECDHE_ECDSA_3DES_EDE_CBC_SHA256: "TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA",
ECDHE_ECDSA_AES_128_CBC_SHA256: "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256",
ECDHE_ECDSA_AES_128_GCM_SHA256: "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256",
ECDHE_ECDSA_AES_256_CBC_SHA384: "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384",
ECDHE_ECDSA_AES_256_GCM_SHA384: "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384",
ECDHE_ECDSA_NULL_SHA256: "TLS_ECDHE_ECDSA_WITH_NULL_SHA",
ECDHE_ECDSA_RC4_128_SHA256: "TLS_ECDHE_ECDSA_WITH_RC4_128_SHA",
ECDHE_RSA_3DES_EDE_CBC_SHA256: "TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA",
ECDHE_RSA_AES_128_CBC_SHA256: "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256",
ECDHE_RSA_AES_128_GCM_SHA256: "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256",
ECDHE_RSA_AES_256_CBC_SHA384: "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384",
ECDHE_RSA_AES_256_GCM_SHA384: "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384",
ECDHE_RSA_NULL_SHA256: "TLS_ECDHE_RSA_WITH_NULL_SHA",
ECDHE_RSA_RC4_128_SHA256: "TLS_ECDHE_RSA_WITH_RC4_128_SHA",
TLS_RSA_WITH_3DES_EDE_CBC_SHA: "TLS_RSA_WITH_3DES_EDE_CBC_SHA",
TLS_RSA_WITH_AES_128_CBC_SHA: "TLS_RSA_WITH_AES_128_CBC_SHA",
TLS_RSA_WITH_AES_128_CBC_SHA256: "TLS_RSA_WITH_AES_128_CBC_SHA256",
TLS_RSA_WITH_AES_128_GCM_SHA256: "TLS_RSA_WITH_AES_128_GCM_SHA256",
TLS_RSA_WITH_AES_256_CBC_SHA: "TLS_RSA_WITH_AES_256_CBC_SHA",
TLS_RSA_WITH_AES_256_CBC_SHA256: "TLS_RSA_WITH_AES_256_CBC_SHA256",
TLS_RSA_WITH_AES_256_GCM_SHA384: "TLS_RSA_WITH_AES_256_GCM_SHA384",
TLS_RSA_WITH_DES_CBC_SHA: "SSL_RSA_WITH_DES_CBC_SHA",
TLS_RSA_WITH_NULL_SHA256: "TLS_RSA_WITH_NULL_SHA256",
TLS_RSA_WITH_RC4_128_SHA256: "SSL_RSA_WITH_RC4_128_SHA",
ANY_TLS12: "*TLS12",
TLS_AES_128_GCM_SHA256: "TLS_AES_128_GCM_SHA256",
TLS_AES_256_GCM_SHA384: "TLS_AES_256_GCM_SHA384",
TLS_CHACHA20_POLY1305_SHA256: "TLS_CHACHA20_POLY1305_SHA256",
TLS_AES_128_CCM_SHA256: "TLS_AES_128_CCM_SHA256",
TLS_AES_128_CCM_8_SHA256: "TLS_AES_128_CCM_8_SHA256",
ANY: "*ANY",
ANY_TLS13: "*TLS13",
ANY_TLS12_OR_HIGHER: "*TLS12ORHIGHER",
ANY_TLS13_OR_HIGHER: "*TLS13ORHIGHER"
}
// List in line with Oracle JRE mappings from https://ibm.biz/mq-cipher-mappings
const ciphers = {
ECDHE_ECDSA_3DES_EDE_CBC_SHA256: 'TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA',
ECDHE_ECDSA_AES_128_CBC_SHA256: 'TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256',
ECDHE_ECDSA_AES_128_GCM_SHA256: 'TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256',
ECDHE_ECDSA_AES_256_CBC_SHA384: 'TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384',
ECDHE_ECDSA_AES_256_GCM_SHA384: 'TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384',
ECDHE_ECDSA_NULL_SHA256: 'TLS_ECDHE_ECDSA_WITH_NULL_SHA',
ECDHE_ECDSA_RC4_128_SHA256: 'TLS_ECDHE_ECDSA_WITH_RC4_128_SHA',
ECDHE_RSA_3DES_EDE_CBC_SHA256: 'TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA',
ECDHE_RSA_AES_128_CBC_SHA256: 'TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256',
ECDHE_RSA_AES_128_GCM_SHA256: 'TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256',
ECDHE_RSA_AES_256_CBC_SHA384: 'TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384',
ECDHE_RSA_AES_256_GCM_SHA384: 'TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384',
ECDHE_RSA_NULL_SHA256: 'TLS_ECDHE_RSA_WITH_NULL_SHA',
ECDHE_RSA_RC4_128_SHA256: 'TLS_ECDHE_RSA_WITH_RC4_128_SHA',
TLS_RSA_WITH_3DES_EDE_CBC_SHA: 'TLS_RSA_WITH_3DES_EDE_CBC_SHA',
TLS_RSA_WITH_AES_128_CBC_SHA: 'TLS_RSA_WITH_AES_128_CBC_SHA',
TLS_RSA_WITH_AES_128_CBC_SHA256: 'TLS_RSA_WITH_AES_128_CBC_SHA256',
TLS_RSA_WITH_AES_128_GCM_SHA256: 'TLS_RSA_WITH_AES_128_GCM_SHA256',
TLS_RSA_WITH_AES_256_CBC_SHA: 'TLS_RSA_WITH_AES_256_CBC_SHA',
TLS_RSA_WITH_AES_256_CBC_SHA256: 'TLS_RSA_WITH_AES_256_CBC_SHA256',
TLS_RSA_WITH_AES_256_GCM_SHA384: 'TLS_RSA_WITH_AES_256_GCM_SHA384',
TLS_RSA_WITH_DES_CBC_SHA: 'SSL_RSA_WITH_DES_CBC_SHA',
TLS_RSA_WITH_NULL_SHA256: 'TLS_RSA_WITH_NULL_SHA256',
TLS_RSA_WITH_RC4_128_SHA256: 'SSL_RSA_WITH_RC4_128_SHA',
ANY_TLS12: '*TLS12',
TLS_AES_128_GCM_SHA256: 'TLS_AES_128_GCM_SHA256',
TLS_AES_256_GCM_SHA384: 'TLS_AES_256_GCM_SHA384',
TLS_CHACHA20_POLY1305_SHA256: 'TLS_CHACHA20_POLY1305_SHA256',
TLS_AES_128_CCM_SHA256: 'TLS_AES_128_CCM_SHA256',
TLS_AES_128_CCM_8_SHA256: 'TLS_AES_128_CCM_8_SHA256',
ANY: '*ANY',
ANY_TLS13: '*TLS13',
ANY_TLS12_OR_HIGHER: '*TLS12ORHIGHER',
ANY_TLS13_OR_HIGHER: '*TLS13ORHIGHER'
};

if (ciphers[cipher] === undefined) {
throw new Error('An invalid cipher spec was provided. Please see https://ibm.biz/mq-cipher-mappings');
}
if (ciphers[cipher] === undefined) {
throw new Error('An invalid cipher spec was provided. Please see https://ibm.biz/mq-cipher-mappings');
}

return ciphers[cipher];
}
return ciphers[cipher];
}
2 changes: 1 addition & 1 deletion components/Files/Models.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function Models(asyncapi, params) {
<File name={`${packagePath}models/${messageNameUpperCase}.java`}>
<PackageDeclaration path={`${params.package}.models`} />
<ImportDeclaration path={`${params.package}.models.ModelContract`} />
<ImportDeclaration path={`java.util.UUID`} />
<ImportDeclaration path={'java.util.UUID'} />

<Class name={messageNameUpperCase} extendsClass="ModelContract">
<Indent size={2} type={IndentationTypes.SPACES}>
Expand Down
26 changes: 9 additions & 17 deletions test/Kafka.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ const crypto = require('crypto');

const MAIN_TEST_RESULT_PATH = path.join('test', 'temp', 'integrationTestResult');


describe('kafka integration tests using the generator', () => {

const generateFolderName = () => {
// You always want to generate to new directory to make sure test runs in clear environment
return path.resolve(MAIN_TEST_RESULT_PATH, crypto.randomBytes(4).toString('hex'));
Expand Down Expand Up @@ -46,11 +44,10 @@ describe('kafka integration tests using the generator', () => {
}

const connectionHelper = readFileSync(path.join(OUTPUT_DIR, `${PACKAGE_PATH}/ConnectionHelper.java`), 'utf-8');
expect(connectionHelper.includes("props.put(\"security.protocol\", \"SASL_SSL\")")).toBe(true);
expect(connectionHelper.includes("props.put(\"sasl.mechanism\", \"SCRAM-SHA-512\")")).toBe(true);
expect(connectionHelper.includes('props.put("security.protocol", "SASL_SSL")')).toBe(true);
expect(connectionHelper.includes('props.put("sasl.mechanism", "SCRAM-SHA-512")')).toBe(true);
});


it('should generate Java for an encrypted Kafka', async () => {
const OUTPUT_DIR = generateFolderName();
const PACKAGE = 'com.custom.package';
Expand Down Expand Up @@ -82,10 +79,9 @@ describe('kafka integration tests using the generator', () => {
}

const connectionHelper = readFileSync(path.join(OUTPUT_DIR, `${PACKAGE_PATH}/ConnectionHelper.java`), 'utf-8');
expect(connectionHelper.includes("props.put(\"security.protocol\", \"SSL\")")).toBe(true);
expect(connectionHelper.includes('props.put("security.protocol", "SSL")')).toBe(true);
});


it('should generate Java for a plain Kafka', async () => {
const OUTPUT_DIR = generateFolderName();
const PACKAGE = 'asyncapi.kafka';
Expand Down Expand Up @@ -118,10 +114,9 @@ describe('kafka integration tests using the generator', () => {
}

const connectionHelper = readFileSync(path.join(OUTPUT_DIR, `${PACKAGE_PATH}/ConnectionHelper.java`), 'utf-8');
expect(connectionHelper.includes("props.put(\"security.protocol\", \"PLAINTEXT\")")).toBe(true);
expect(connectionHelper.includes('props.put("security.protocol", "PLAINTEXT")')).toBe(true);
});


it('should generate Java for a secured Kafka', async () => {
const OUTPUT_DIR = generateFolderName();
const PACKAGE = 'asyncapi.kafka';
Expand Down Expand Up @@ -151,11 +146,10 @@ describe('kafka integration tests using the generator', () => {
expect(existsSync(path.join(OUTPUT_DIR, file))).toBe(true);
}
const connectionHelper = readFileSync(path.join(OUTPUT_DIR, `${PACKAGE_PATH}/ConnectionHelper.java`), 'utf-8');
expect(connectionHelper.includes("props.put(\"security.protocol\", \"SASL_PLAINTEXT\")")).toBe(true);
expect(connectionHelper.includes("props.put(\"sasl.mechanism\", \"PLAIN\")")).toBe(true);
expect(connectionHelper.includes('props.put("security.protocol", "SASL_PLAINTEXT")')).toBe(true);
expect(connectionHelper.includes('props.put("sasl.mechanism", "PLAIN")')).toBe(true);
});


it('should generate Java for the streetlights example', async () => {
const OUTPUT_DIR = generateFolderName();
const PACKAGE = 'com.asyncapi.examples.streetlights.v2';
Expand Down Expand Up @@ -190,10 +184,9 @@ describe('kafka integration tests using the generator', () => {
expect(existsSync(path.join(OUTPUT_DIR, file))).toBe(true);
}
const connectionHelper = readFileSync(path.join(OUTPUT_DIR, `${PACKAGE_PATH}/ConnectionHelper.java`), 'utf-8');
expect(connectionHelper.includes("props.put(\"security.protocol\", \"SSL\")")).toBe(true);
expect(connectionHelper.includes('props.put("security.protocol", "SSL")')).toBe(true);
});


it('should generate Java for a v3 AsyncAPI', async () => {
const OUTPUT_DIR = generateFolderName();
console.log(OUTPUT_DIR);
Expand Down Expand Up @@ -229,8 +222,7 @@ describe('kafka integration tests using the generator', () => {
expect(existsSync(path.join(OUTPUT_DIR, file))).toBe(true);
}
const connectionHelper = readFileSync(path.join(OUTPUT_DIR, `${PACKAGE_PATH}/ConnectionHelper.java`), 'utf-8');
expect(connectionHelper.includes("props.put(\"security.protocol\", \"SASL_SSL\")")).toBe(true);
expect(connectionHelper.includes("props.put(\"sasl.mechanism\", \"SCRAM-SHA-256\")")).toBe(true);
expect(connectionHelper.includes('props.put("security.protocol", "SASL_SSL")')).toBe(true);
expect(connectionHelper.includes('props.put("sasl.mechanism", "SCRAM-SHA-256")')).toBe(true);
});

});

0 comments on commit 66a4538

Please sign in to comment.