Skip to content

Commit 30538c8

Browse files
Merge pull request #230 from iqmessenger-bv/accessTokenConnection
Access token connection
2 parents 85779a8 + ce99fc9 commit 30538c8

File tree

12 files changed

+194
-18
lines changed

12 files changed

+194
-18
lines changed

RMQClient.xcodeproj/project.pbxproj

+4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
/* Begin PBXBuildFile section */
1010
1029A0E22087A97E00C72924 /* ConnectionDeadlockTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1029A0E12087A97E00C72924 /* ConnectionDeadlockTests.swift */; };
1111
4DF6E46D27F6E98100C43208 /* RMQClient.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AEE7FE911C3BCA6000DF8C4F /* RMQClient.framework */; };
12+
5CE0C5292B873842000087B7 /* ConnectionUpdateSecretTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5CE0C5282B873842000087B7 /* ConnectionUpdateSecretTest.swift */; };
1213
70311B0B21ED538600AE1804 /* RMQConnectionDefaults.h in Headers */ = {isa = PBXBuildFile; fileRef = 70311B0A21ED538600AE1804 /* RMQConnectionDefaults.h */; };
1314
70338A2421FBAA7C00C9069D /* TLSConnectionIntegrationTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 70338A2321FBAA7C00C9069D /* TLSConnectionIntegrationTest.swift */; };
1415
705359A921D174A400CF6456 /* TestCertificates in Resources */ = {isa = PBXBuildFile; fileRef = 705359A821D174A400CF6456 /* TestCertificates */; };
@@ -238,6 +239,7 @@
238239
/* Begin PBXFileReference section */
239240
1029A0E12087A97E00C72924 /* ConnectionDeadlockTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConnectionDeadlockTests.swift; sourceTree = "<group>"; };
240241
4DF6E43627F6E90700C43208 /* MemoryTest.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MemoryTest.app; sourceTree = BUILT_PRODUCTS_DIR; };
242+
5CE0C5282B873842000087B7 /* ConnectionUpdateSecretTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConnectionUpdateSecretTest.swift; sourceTree = "<group>"; };
241243
70311B0A21ED538600AE1804 /* RMQConnectionDefaults.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RMQConnectionDefaults.h; sourceTree = "<group>"; };
242244
70338A2321FBAA7C00C9069D /* TLSConnectionIntegrationTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TLSConnectionIntegrationTest.swift; sourceTree = "<group>"; };
243245
705359A821D174A400CF6456 /* TestCertificates */ = {isa = PBXFileReference; lastKnownFileType = folder; path = TestCertificates; sourceTree = SOURCE_ROOT; };
@@ -491,6 +493,7 @@
491493
AE26FA2F1C970E9A00CDBBAA /* Channels */ = {
492494
isa = PBXGroup;
493495
children = (
496+
5CE0C5282B873842000087B7 /* ConnectionUpdateSecretTest.swift */,
494497
AE26FA2D1C970DF100CDBBAA /* RMQChannelContract.swift */,
495498
AE8279841C8D86110013ADD1 /* ChannelAllocationTest.swift */,
496499
AE8AD2681CC545ED00229444 /* RMQFramesetValidatorTest.swift */,
@@ -1292,6 +1295,7 @@
12921295
AE9DB00D1D12AA120005F44B /* RMQTransactionalConfirmationsTest.swift in Sources */,
12931296
AE11F1B21D155C8A007AD330 /* RMQMessageTest.swift in Sources */,
12941297
AE9DB0091D11FDED0005F44B /* ConfirmationsSpy.swift in Sources */,
1298+
5CE0C5292B873842000087B7 /* ConnectionUpdateSecretTest.swift in Sources */,
12951299
AEA8A7621CC97C7900371E38 /* RMQGCDSerialQueueTest.swift in Sources */,
12961300
AE59345B1C8735FA00560A73 /* ChannelSpy.swift in Sources */,
12971301
AE8AD25C1CC4E67F00229444 /* RMQUnallocatedChannelTest.swift in Sources */,

RMQClient/RMQConnection.h

+10
Original file line numberDiff line numberDiff line change
@@ -242,4 +242,14 @@
242242
*/
243243
- (nonnull id<RMQChannel>)createChannel;
244244

245+
/*!
246+
* @brief Update secret.
247+
* This method updates the secret used to authenticate this connection.
248+
* It is used when secrets have an expiration date and need to be renewed, like OAuth 2 tokens.
249+
* @param secret The new secret.
250+
* @param reason The reason for the secret update.
251+
*/
252+
- (void)updateSecret:(nonnull NSString *)secret
253+
reason:(nonnull NSString *)reason;
254+
245255
@end

RMQClient/RMQConnection.m

+16
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,14 @@ - (void)start {
608608
return ch;
609609
}
610610

611+
- (void)updateSecret:(NSString *)secret
612+
reason:(NSString *)reason
613+
{
614+
[self.commandQueue enqueue:^{
615+
[self sendFrameset:[[RMQFrameset alloc] initWithChannelNumber:@0 method:[self methodForUpdateSecret:secret reason:reason]]];
616+
}];
617+
}
618+
611619
- (BOOL)hasCompletedHandshake {
612620
return self.handshakeComplete;
613621
}
@@ -746,6 +754,14 @@ - (void)closeAllUserChannels {
746754
}
747755
}
748756

757+
- (RMQConnectionUpdateSecret *)methodForUpdateSecret:(NSString *)secret
758+
reason:(NSString *)reason {
759+
RMQLongstr *secretLongstr = [[RMQLongstr alloc] init:secret];
760+
RMQShortstr *reasonShortstr = [[RMQShortstr alloc] init:reason];
761+
return [[RMQConnectionUpdateSecret alloc] initWithSecret:secretLongstr
762+
reason:reasonShortstr];
763+
}
764+
749765
- (RMQConnectionClose *)amqClose {
750766
return [[RMQConnectionClose alloc] initWithReplyCode:[[RMQShort alloc] init:200]
751767
replyText:[[RMQShortstr alloc] init:@"Goodbye"]

RMQClient/RMQMethodMap.m

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ + (NSDictionary *)methodMap {
1818
@[@(10), @(51)] : [RMQConnectionCloseOk class],
1919
@[@(10), @(60)] : [RMQConnectionBlocked class],
2020
@[@(10), @(61)] : [RMQConnectionUnblocked class],
21+
@[@(10), @(70)] : [RMQConnectionUpdateSecret class],
22+
@[@(10), @(71)] : [RMQConnectionUpdateSecretOk class],
2123
@[@(20), @(10)] : [RMQChannelOpen class],
2224
@[@(20), @(11)] : [RMQChannelOpenOk class],
2325
@[@(20), @(20)] : [RMQChannelFlow class],

RMQClient/RMQMethods.h

+9
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,15 @@ typedef NS_OPTIONS(NSUInteger, RMQConnectionOpenOptions) {
8686
@end
8787
@interface RMQConnectionUnblocked : RMQValue <RMQMethod>
8888

89+
@end
90+
@interface RMQConnectionUpdateSecret : RMQValue <RMQMethod>
91+
@property (nonnull, copy, nonatomic, readonly) RMQLongstr *secret;
92+
@property (nonnull, copy, nonatomic, readonly) RMQShortstr *reason;
93+
- (nonnull instancetype)initWithSecret:(nonnull RMQLongstr *)secret
94+
reason:(nonnull RMQShortstr *)reason;
95+
@end
96+
@interface RMQConnectionUpdateSecretOk : RMQValue <RMQMethod>
97+
8998
@end
9099
@interface RMQChannelOpen : RMQValue <RMQMethod>
91100
@property (nonnull, copy, nonatomic, readonly) RMQShortstr *reserved1;

RMQClient/RMQMethods.m

+91
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,97 @@ - (NSNumber *)frameTypeID { return @1; }
639639
- (BOOL)hasContent { return NO; }
640640

641641

642+
- (instancetype)initWithDecodedFrame:(NSArray *)frame {
643+
self = [super init];
644+
if (self) {
645+
self.payloadArguments = @[];
646+
}
647+
return self;
648+
}
649+
650+
- (NSData *)amqEncoded {
651+
NSMutableData *encoded = [NSMutableData new];
652+
[encoded appendData:[[RMQShort alloc] init:self.classID.integerValue].amqEncoded];
653+
[encoded appendData:[[RMQShort alloc] init:self.methodID.integerValue].amqEncoded];
654+
for (id<RMQEncodable>arg in self.payloadArguments) {
655+
[encoded appendData:arg.amqEncoded];
656+
}
657+
return encoded;
658+
}
659+
660+
@end
661+
662+
@interface RMQConnectionUpdateSecret ()
663+
@property (nonnull, copy, nonatomic, readwrite) RMQLongstr *secret;
664+
@property (nonnull, copy, nonatomic, readwrite) RMQShortstr *reason;
665+
@property (nonatomic, readwrite) NSArray *payloadArguments;
666+
@property (nonatomic, readwrite) BOOL hasContent;
667+
@end
668+
669+
@implementation RMQConnectionUpdateSecret
670+
671+
+ (NSArray *)propertyClasses {
672+
return @[[RMQLongstr class],
673+
[RMQShortstr class]];
674+
}
675+
- (NSNumber *)classID { return @10; }
676+
- (NSNumber *)methodID { return @70; }
677+
- (Class)syncResponse { return [RMQConnectionUpdateSecretOk class]; }
678+
- (NSNumber *)frameTypeID { return @1; }
679+
- (BOOL)hasContent { return NO; }
680+
681+
- (nonnull instancetype)initWithSecret:(nonnull RMQLongstr *)secret
682+
reason:(nonnull RMQShortstr *)reason {
683+
self = [super init];
684+
if (self) {
685+
self.secret = secret;
686+
self.reason = reason;
687+
self.payloadArguments = @[self.secret,
688+
self.reason];
689+
}
690+
return self;
691+
}
692+
693+
- (instancetype)initWithDecodedFrame:(NSArray *)frame {
694+
self = [super init];
695+
if (self) {
696+
self.secret = ((RMQLongstr *)frame[0]);
697+
self.reason = ((RMQShortstr *)frame[1]);
698+
self.payloadArguments = @[self.secret,
699+
self.reason];
700+
}
701+
return self;
702+
}
703+
704+
- (NSData *)amqEncoded {
705+
NSMutableData *encoded = [NSMutableData new];
706+
[encoded appendData:[[RMQShort alloc] init:self.classID.integerValue].amqEncoded];
707+
[encoded appendData:[[RMQShort alloc] init:self.methodID.integerValue].amqEncoded];
708+
for (id<RMQEncodable>arg in self.payloadArguments) {
709+
[encoded appendData:arg.amqEncoded];
710+
}
711+
return encoded;
712+
}
713+
714+
@end
715+
716+
@interface RMQConnectionUpdateSecretOk ()
717+
@property (nonatomic, readwrite) NSArray *payloadArguments;
718+
@property (nonatomic, readwrite) BOOL hasContent;
719+
@end
720+
721+
@implementation RMQConnectionUpdateSecretOk
722+
723+
+ (NSArray *)propertyClasses {
724+
return @[];
725+
}
726+
- (NSNumber *)classID { return @10; }
727+
- (NSNumber *)methodID { return @71; }
728+
- (Class)syncResponse { return nil; }
729+
- (NSNumber *)frameTypeID { return @1; }
730+
- (BOOL)hasContent { return NO; }
731+
732+
642733
- (instancetype)initWithDecodedFrame:(NSArray *)frame {
643734
self = [super init];
644735
if (self) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//
2+
// ConnectionUpdateSecretTest.swift
3+
// RMQClientTests
4+
//
5+
// Created by Andrew Urban on 22.02.2024.
6+
// Copyright © 2024 VMware. All rights reserved.
7+
//
8+
9+
import XCTest
10+
11+
final class ConnectionUpdateSecretTest: XCTestCase {
12+
13+
func testSendsUpdateSecretMethod() {
14+
let (transport, q, conn, _) = ConnectionWithFakesHelper.connectionAfterHandshake()
15+
16+
let secret = "someSecret"
17+
let reason = "some test reason"
18+
19+
conn.updateSecret(secret, reason: reason);
20+
21+
try? q.step()
22+
23+
transport.assertClientSentMethod(MethodFixtures.connectionUpdateSecret(secret, reason: reason), channelNumber: 0)
24+
}
25+
26+
}

RMQClientTests/MethodFixtures.swift

+5
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,11 @@ class MethodFixtures {
214214
static func connectionTuneOk() -> RMQConnectionTuneOk {
215215
return RMQConnectionTuneOk(channelMax: RMQShort(65535), frameMax: RMQLong(RMQFrameMax), heartbeat: RMQShort(60))
216216
}
217+
218+
static func connectionUpdateSecret(_ secret: String,
219+
reason: String) -> RMQConnectionUpdateSecret {
220+
return RMQConnectionUpdateSecret(secret: RMQLongstr(secret), reason: RMQShortstr(reason))
221+
}
217222

218223
static func exchangeBind(_ source: String, destination: String, routingKey: String) -> RMQExchangeBind {
219224
return RMQExchangeBind(destination: destination, source: source, routingKey: routingKey)

codegen/amqp0-9-1.extended.xml

+30
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
WARNING: Modified from the official 0-9-1 specification XML by
55
the addition of:
66
confirm.select and confirm.select-ok,
7+
connection.update-secret and connection.update-secret-ok,
78
exchange.bind and exchange.bind-ok,
89
exchange.unbind and exchange.unbind-ok,
910
basic.nack,
@@ -914,6 +915,35 @@
914915
<chassis name = "server" implement = "MUST"/>
915916
<chassis name = "client" implement = "MUST"/>
916917
</method>
918+
919+
<method name = "update-secret" synchronous = "1" index = "70" label = "update secret">
920+
<doc>
921+
This method updates the secret used to authenticate this connection. It is used when secrets have an expiration date and need to be renewed, like OAuth 2 tokens.
922+
</doc>
923+
924+
<chassis name = "client" implement = "MUST" />
925+
<response name = "update-secret-ok" />
926+
927+
<field name = "secret" domain = "longstr">
928+
<doc>
929+
The new secret.
930+
</doc>
931+
</field>
932+
933+
<field name = "reason" domain = "shortstr">
934+
<doc>
935+
The reason for the secret update.
936+
</doc>
937+
</field>
938+
</method>
939+
940+
<method name = "update-secret-ok" synchronous = "1" index = "71" label = "update secret response">
941+
<doc>
942+
This method confirms the updated secret is valid.
943+
</doc>
944+
<chassis name = "server" implement = "MUST" />
945+
</method>
946+
917947
</class>
918948

919949
<!-- == CHANNEL ========================================================== -->

docker/Dockerfile

+1-13
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,4 @@
1-
FROM ubuntu:18.04
2-
3-
RUN apt-get update -y
4-
RUN apt-get install -y gnupg2 wget
5-
RUN wget -O - "https://github.com/rabbitmq/signing-keys/releases/download/2.0/rabbitmq-release-signing-key.asc" | apt-key add -
6-
7-
COPY apt/sources.list.d/bintray.rabbitmq.list /etc/apt/sources.list.d/bintray.rabbitmq.list
8-
COPY apt/preferences.d/erlang /etc/apt/preferences.d/erlang
9-
10-
RUN apt-get update -y
11-
12-
RUN apt-get upgrade -y && \
13-
apt-get install -y rabbitmq-server
1+
FROM rabbitmq:3.12-management
142

153
COPY docker-entrypoint.sh /
164
COPY certificates/*.pem /etc/rabbitmq/

docker/apt/preferences.d/erlang

-3
This file was deleted.

docker/apt/sources.list.d/bintray.rabbitmq.list

-2
This file was deleted.

0 commit comments

Comments
 (0)