Skip to content

Commit be3316a

Browse files
authored
2.12.2 (#67)
* Fix dependencies * Update to 2.12.2 * Add oauth test case
1 parent b313daf commit be3316a

File tree

7 files changed

+70
-32
lines changed

7 files changed

+70
-32
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
- name: Show python version
4141
run: python3 --version
4242
- name: Execute tests
43-
run: python3 -m robot -d ./docs examples/
43+
run: cd examples && python3 -m robot -d ../docs .
4444
- name: Archive test log
4545
if: ${{ always() }}
4646
uses: actions/upload-artifact@v4

examples/docker-compose.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
version: '3.8'
21
services:
32
broker:
43
image: confluentinc/cp-server:7.8.0

examples/oauth2_test.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import time
2+
import functools
3+
import json
4+
from robot.libraries.BuiltIn import BuiltIn
5+
6+
7+
def create_test_token():
8+
"""Create a test OAuth2 token for unsecured testing"""
9+
token_payload = {
10+
"sub": "test-user",
11+
"iss": "test-issuer",
12+
"aud": "kafka",
13+
"exp": int(time.time()) + 3600,
14+
"iat": int(time.time()),
15+
"scope": "kafka-producer kafka-consumer"
16+
}
17+
18+
import base64
19+
token_json = json.dumps(token_payload)
20+
test_token = base64.b64encode(token_json.encode()).decode()
21+
22+
return test_token
23+
24+
25+
def oauth_cb_test_producer(oauth_config):
26+
BuiltIn().set_global_variable("${SEEN_RF_OAUTH_CB_PRODUCER}", True)
27+
test_token = create_test_token()
28+
expiry_time = time.time() + 3600
29+
BuiltIn().log(f"Generated test token: {test_token[:50]}...")
30+
return test_token, expiry_time
31+
32+
33+
def oauth_cb_test_consumer(oauth_config):
34+
BuiltIn().set_global_variable("${SEEN_RF_OAUTH_CB_CONSUMER}", True)
35+
test_token = create_test_token()
36+
expiry_time = time.time() + 3600
37+
38+
return test_token, expiry_time
39+
40+
41+
def get_test_producer_token(oauth_config=None):
42+
return functools.partial(oauth_cb_test_producer, oauth_config or {})
43+
44+
45+
def get_test_consumer_token(oauth_config=None):
46+
return functools.partial(oauth_cb_test_consumer, oauth_config or {})

examples/oauth_example.py

Lines changed: 0 additions & 11 deletions
This file was deleted.

examples/test_oauth.robot

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,32 @@
11
*** Settings ***
22
Library ConfluentKafkaLibrary
3-
Library oauth_example
3+
Library oauth2_test
44
Library Collections
55
Library String
66

77

88
*** Variables ***
9-
${SEEN_RF_OAUTH_CB} ${False}
9+
${SEEN_RF_OAUTH_CB_PRODUCER} ${False}
10+
${SEEN_RF_OAUTH_CB_CONSUMER} ${False}
11+
${KAFKA_BOOTSTRAP_SERVERS} localhost:9092
12+
${TEST_TOPIC} oauth2-test-topic
1013

1114

1215
*** Test Cases ***
13-
Example Oauth
14-
[Documentation] Example of how to use OAUTH with library and call functools
15-
... via get_token function. For better handling there could be
16-
... some global variable which can be set inside of python lib.
17-
... Not executable right now, needs update env (issue #21).
16+
Test OAuth2 Token Generation
17+
${test_token}= oauth2_test.create_test_token
18+
Should Not Be Empty ${test_token}
19+
${producer_token_func}= oauth2_test.get_test_producer_token
20+
${consumer_token_func}= oauth2_test.get_test_consumer_token
1821

19-
Skip
2022

23+
Test OAuth2 Library Integration
2124
${string_serializer}= Get String Serializer
22-
${value_serializer}= Get String Serializer
23-
24-
# This returns: functools.partial(<function oauth_cb at 0x7f...>, 'configuration')
25-
${fun}= oauth_example.get_token configuration
26-
27-
${producer_id}= Create Producer key_serializer=${string_serializer} value_serializer=${value_serializer} legacy=${False} security.protocol=sasl_plaintext sasl.mechanisms=OAUTHBEARER oauth_cb=${fun}
28-
29-
#...
25+
${oauth_func}= oauth2_test.get_test_producer_token
26+
27+
${status} ${error}= Run Keyword And Ignore Error
28+
... Create Producer localhost:9092
29+
... oauth_cb=${oauth_func}
30+
... security.protocol=sasl_plaintext
31+
... sasl.mechanisms=OAUTHBEARER
32+
Should Be Equal ${status} PASS

pyproject.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ classifiers = [
2121
requires-python = ">=3.8"
2222
dependencies = [
2323
"robotframework >= 3.2.1",
24-
"confluent-kafka == 2.12.0",
24+
"confluent-kafka == 2.12.2",
2525
"requests >= 2.25.1",
2626
]
2727

@@ -36,6 +36,7 @@ avro = [
3636
json = [
3737
"jsonschema >= 3.2.0",
3838
"pyrsistent >= 0.20.0",
39+
"orjson >= 3.10",
3940
]
4041
protobuf = [
4142
"protobuf >= 4.22.0",
@@ -45,8 +46,8 @@ schemaregistry = [
4546
"httpx>=0.26",
4647
"cachetools >= 5.5.0",
4748
"attrs >= 24.3.0",
49+
"certifi",
4850
"authlib >= 1.0.0",
49-
"orjson >= 3.10",
5051
]
5152
all = [
5253
"robotframework-confluentkafkalibrary[avro]",
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
VERSION = '2.12.0.post1'
1+
VERSION = '2.12.2.post1'

0 commit comments

Comments
 (0)