Skip to content

Commit

Permalink
move nkeys
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubwro committed Oct 7, 2023
1 parent c4ffc9e commit cbce3ed
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 25 deletions.
16 changes: 8 additions & 8 deletions src/connection/connect.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ function default_connect_options()
end

function validate_connect_options(server_info::Info, options)
# TODO: check if proto is 1 when `echo` flag is set

# TODO: maybe better to rely on server side validation. Grab Err messages and decide if conn should be terminated.
server_info.proto > 0 || error("Server supports too old protocol version.")
server_info.headers || error("Server does not support headers.") # TODO: maybe this can be relaxed.
Expand Down Expand Up @@ -127,22 +129,20 @@ end
"""
connect([host, port; options...])
Connect to NATS server.
Connect is a blocking operation that initiazlies connection.
Connect to NATS server. The function is blocking until connection is initialized.
Options are:
- `default`: sets connection as a default connection. Default connection is used when no connection is specified.
- `reconnect_delays`: vector of delays that reconnect is performed until connected again. Default is $RECONNECT_DELAYS.
- `outbox_size`: size of outbox buffer for cient messages. Default is $OUTBOX_SIZE. If to small operations may throw exceptions.
- `verbose: turns on `+OK` protocol acknowledgements
- `default`: boolean flag that indicated if a connection should be set as default which will be used when no connection specified
- `reconnect_delays`: vector of delays that reconnect is performed until connected again. Default is $RECONNECT_DELAYS
- `outbox_size`: size of outbox buffer for cient messages. Default is $OUTBOX_SIZE, if to small operations that send messages to server (e.g. `publish`) may throw an exception
- `verbose: turns on protocol acknowledgements
- `pedantic: turns on additional strict format checking, e.g. for properly formed subjects
- `tls_required: indicates whether the client requires an SSL connection
- `auth_token`: client authorization token
- `user`: connection username
- `pass`: connection password
- `name`: client name
- `echo`: if set to `false`, the server (version 1.2.0+) will not send originating messages from this connection to its own subscriptions. Clients should set this to `false` only for server supporting this feature, which is when `proto` in the `INFO` protocol is set to at least `1`
- `echo`: if set to `false`, the server will not send originating messages from this connection to its own subscriptions
- `jwt`: the JWT that identifies a user permissions and account.
- `no_responders`: enable quick replies for cases where a request is sent to a topic with no responders.
- `headers`: whether the client supports headers
Expand Down
1 change: 0 additions & 1 deletion src/connection/connection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ end

include("utils.jl")
include("tls.jl")
include("nkeys.jl")
include("send.jl")
include("handlers.jl")
include("drain.jl")
Expand Down
1 change: 1 addition & 0 deletions src/connection/drain.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ function drain(nc::Connection)
for (_, sub) in nc.subs
unsubscribe(sub; max_msgs = 0, connection = nc)
end
# TODO: wait for handlers running == 0
sleep(3)
length(nc.subs) > 0 && @warn "$(length(nc.subs)) not unsubscribed during drain."
status(nc, DRAINED)
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions src/protocol/protocol.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ include("payload.jl")
include("headers.jl")
include("convert.jl")
include("show.jl")
include("nkeys.jl")
16 changes: 0 additions & 16 deletions test/connection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -125,22 +125,6 @@ end
@test_throws "Client requires TLS but it is not available for the server." NATS.connect(default = false, tls_required = true)
end


@testset "Nonce signatures" begin
seed = "SUAJ4LZRG3KF7C7U4E5737YMAOGUAWBODUM6DBWLY4UPUMXH6TH7JLQFDM"
nkey = "UAGPV4UFVS34M2XGY7HLSNEBDVJZZDZ6XMQ4NTXVEMKZQNSFH2AJFUA5"
nonce = "XTdilcu9paonaBQ"
sig = "3tsErI9fNKHWOHLAbc_XQ8Oo3XHv__7I_fA1aQ7xod3gYpxhDzt1vItbQLv3FhDtDFycxJJ0wA26rG3NEwWZBg"
@test NATS.sign(nonce, seed) == sig

seed = "SUADPKZWX3XJQO4GJEX2IGZAKCYUSLSLNJXFG7KPAYAODEVABRK6ZKKALA"
nkey= "UDBKUC5JFUX5SDF6CGBT3WAZEZSJTGMWWSCRJMODEUPVOKBPCLVODH2J"
nonce = "HiA_hND1AV-DjmM"
sig = "g4HDazX_ZZig_FOFBzhorLSYCEDRlv20Y5vErFjDlTRZMqaaF27ImP16es_GI83Fn59xr9V98Ux5GlEvvaeADQ"
@test NATS.sign(nonce, seed) == sig
end


@testset "Subscription warnings" begin
nc = NATS.connect()

Expand Down
14 changes: 14 additions & 0 deletions test/protocol.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,17 @@ end
@test String(repr(MIME_HEADERS(), ["A" => "B"])) == "NATS/1.0\r\nA: B\r\n\r\n"
@test String(repr(MIME_HEADERS(), (nothing, nothing))) == ""
end

@testset "Nonce signatures" begin
seed = "SUAJ4LZRG3KF7C7U4E5737YMAOGUAWBODUM6DBWLY4UPUMXH6TH7JLQFDM"
nkey = "UAGPV4UFVS34M2XGY7HLSNEBDVJZZDZ6XMQ4NTXVEMKZQNSFH2AJFUA5"
nonce = "XTdilcu9paonaBQ"
sig = "3tsErI9fNKHWOHLAbc_XQ8Oo3XHv__7I_fA1aQ7xod3gYpxhDzt1vItbQLv3FhDtDFycxJJ0wA26rG3NEwWZBg"
@test NATS.sign(nonce, seed) == sig

seed = "SUADPKZWX3XJQO4GJEX2IGZAKCYUSLSLNJXFG7KPAYAODEVABRK6ZKKALA"
nkey= "UDBKUC5JFUX5SDF6CGBT3WAZEZSJTGMWWSCRJMODEUPVOKBPCLVODH2J"
nonce = "HiA_hND1AV-DjmM"
sig = "g4HDazX_ZZig_FOFBzhorLSYCEDRlv20Y5vErFjDlTRZMqaaF27ImP16es_GI83Fn59xr9V98Ux5GlEvvaeADQ"
@test NATS.sign(nonce, seed) == sig
end

0 comments on commit cbce3ed

Please sign in to comment.