Skip to content

Commit

Permalink
Add repro as test.
Browse files Browse the repository at this point in the history
  • Loading branch information
dgyimesi committed Jun 3, 2022
1 parent ec78a0e commit 61051b1
Showing 1 changed file with 58 additions and 3 deletions.
61 changes: 58 additions & 3 deletions src/admin/__tests__/createAcls.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const createAdmin = require('../index')
const createProducer = require('../../producer/index')

const {
secureRandom,
Expand All @@ -13,7 +14,7 @@ const ACL_OPERATION_TYPES = require('../../protocol/aclOperationTypes')
const ACL_PERMISSION_TYPES = require('../../protocol/aclPermissionTypes')
const RESOURCE_PATTERN_TYPES = require('../../protocol/resourcePatternTypes')

const createSASLAdminClientForUser = ({ username, password }) => {
const createSASLClientForUser = createClient => ({ username, password }) => {
const saslConnectionOpts = () => {
return Object.assign(sslConnectionOpts(), {
port: 9094,
Expand All @@ -25,7 +26,7 @@ const createSASLAdminClientForUser = ({ username, password }) => {
})
}

const admin = createAdmin({
const client = createClient({
logger: newLogger(),
cluster: createCluster(
{
Expand All @@ -36,9 +37,12 @@ const createSASLAdminClientForUser = ({ username, password }) => {
),
})

return admin
return client
}

const createSASLAdminClientForUser = createSASLClientForUser(createAdmin)
const createSASLProducerClientForUser = createSASLClientForUser(createProducer)

describe('Admin', () => {
let admin

Expand Down Expand Up @@ -247,5 +251,56 @@ describe('Admin', () => {

await expect(admin.fetchTopicMetadata({ topics: [topicName] })).resolves.toBeTruthy()
})

test('can produce to allowed topic after failing to produce to not-allowed topic', async () => {
const allowedTopic = `allowed-${secureRandom()}`
const notAllowedTopic = `disallowed-${secureRandom()}`

admin = createSASLAdminClientForUser({ username: 'test', password: 'testtest' })

await admin.connect()
await admin.createTopics({
waitForLeaders: true,
topics: [allowedTopic, notAllowedTopic].map(topic => ({ topic, numPartitions: 1 })),
})
await admin.createAcls({
acl: [
{
resourceType: ACL_RESOURCE_TYPES.TOPIC,
resourceName: notAllowedTopic,
resourcePatternType: RESOURCE_PATTERN_TYPES.LITERAL,
principal: 'User:bob',
host: '*',
operation: ACL_OPERATION_TYPES.WRITE,
permissionType: ACL_PERMISSION_TYPES.DENY,
},
{
resourceType: ACL_RESOURCE_TYPES.TOPIC,
resourceName: allowedTopic,
resourcePatternType: RESOURCE_PATTERN_TYPES.LITERAL,
principal: 'User:bob',
host: '*',
operation: ACL_OPERATION_TYPES.WRITE,
permissionType: ACL_PERMISSION_TYPES.ALLOW,
},
],
})

await admin.disconnect()
const producer = createSASLProducerClientForUser({ username: 'bob', password: 'bobbob' })
await producer.connect()

await expect(
producer.send({ topic: allowedTopic, messages: [{ value: 'hello' }] })
).resolves.not.toBeUndefined()
await expect(
producer.send({ topic: notAllowedTopic, messages: [{ value: 'whoops' }] })
).rejects.not.toBeUndefined()
await expect(
producer.send({ topic: allowedTopic, messages: [{ value: 'world' }] })
).resolves.not.toBeUndefined()

await producer.disconnect()
})
})
})

0 comments on commit 61051b1

Please sign in to comment.