Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PPT-1545 fix signage request issue #394

Merged
merged 3 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions OPENAPI_DOC.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17998,7 +17998,7 @@ paths:
content:
application/json:
schema:
$ref: '#/components/schemas/NamedTuple_type__Symbol__signature__NamedTuple_verb__String__url__String__headers__Hash_String__String____upload_id__String___Nil_'
$ref: '#/components/schemas/NamedTuple_type__Symbol__signature__NamedTuple_verb__String__url__String__headers__Hash_String__String____upload_id__String___Nil__body__String___Nil_'
409:
description: Conflict
content:
Expand Down Expand Up @@ -18227,7 +18227,7 @@ paths:
content:
application/json:
schema:
$ref: '#/components/schemas/_NamedTuple_ok__Bool____NamedTuple_type__Symbol__signature__NamedTuple_verb__String__url__String__headers__Hash_String__String____upload_id__String___Nil__'
$ref: '#/components/schemas/_NamedTuple_ok__Bool____NamedTuple_type__Symbol__signature__NamedTuple_verb__String__url__String__headers__Hash_String__String____upload_id__String___Nil__body__String___Nil__'
409:
description: Conflict
content:
Expand Down Expand Up @@ -26586,7 +26586,7 @@ components:
- type
- signature
- residence
? NamedTuple_type__Symbol__signature__NamedTuple_verb__String__url__String__headers__Hash_String__String____upload_id__String___Nil_
? NamedTuple_type__Symbol__signature__NamedTuple_verb__String__url__String__headers__Hash_String__String____upload_id__String___Nil__body__String___Nil_
: type: object
properties:
type:
Expand All @@ -26609,6 +26609,9 @@ components:
upload_id:
type: string
nullable: true
body:
type: string
nullable: true
required:
- type
- signature
Expand All @@ -26635,6 +26638,9 @@ components:
part:
type: integer
format: Int32
block_id:
type: string
nullable: true
required:
- md5
- part
Expand All @@ -26648,7 +26654,7 @@ components:
part_update:
type: boolean
nullable: true
? _NamedTuple_ok__Bool____NamedTuple_type__Symbol__signature__NamedTuple_verb__String__url__String__headers__Hash_String__String____upload_id__String___Nil__
? _NamedTuple_ok__Bool____NamedTuple_type__Symbol__signature__NamedTuple_verb__String__url__String__headers__Hash_String__String____upload_id__String___Nil__body__String___Nil__
: anyOf:
- type: object
properties:
Expand Down Expand Up @@ -26678,6 +26684,9 @@ components:
upload_id:
type: string
nullable: true
body:
type: string
nullable: true
required:
- type
- signature
Expand Down
20 changes: 12 additions & 8 deletions shard.lock
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ shards:
git: https://github.com/taylorfinnell/awscr-signer.git
version: 0.8.2

azblob:
git: https://github.com/spider-gazelle/azblob.cr.git
version: 0.1.0+git.commit.16b822289fca1703cafc9dc9206733e86656e01c

backtracer:
git: https://github.com/sija/backtracer.cr.git
version: 1.2.2
Expand Down Expand Up @@ -63,7 +67,7 @@ shards:

csuuid:
git: https://github.com/wyhaines/csuuid.cr.git
version: 1.0.1+git.commit.4cb8656a9214aede9c1840cad4acf8e55e658f2f
version: 1.0.2

db:
git: https://github.com/crystal-lang/crystal-db.git
Expand Down Expand Up @@ -163,7 +167,7 @@ shards:

nbchannel:
git: https://github.com/wyhaines/nbchannel.cr.git
version: 0.1.0+git.commit.a8f5be6aa198abfa9f1893e1156640b8ea526094
version: 0.1.0

neuroplastic:
git: https://github.com/spider-gazelle/neuroplastic.git
Expand All @@ -183,15 +187,15 @@ shards:

opentelemetry-api:
git: https://github.com/wyhaines/opentelemetry-api.cr.git
version: 0.5.0
version: 0.5.1

opentelemetry-instrumentation:
git: https://github.com/wyhaines/opentelemetry-instrumentation.cr.git
version: 0.5.4+git.commit.9b26aabef208b9eb0bf4612788362fa41768790b

opentelemetry-sdk: # Overridden
git: https://github.com/wyhaines/opentelemetry-sdk.cr.git
version: 0.6.1+git.commit.addc3c740d5ea8e61ffd9500fe32ebf21210d66c
version: 0.6.3+git.commit.470e34105727b039aee2bb3650e907bf6eefc971

pars: # Overridden
git: https://github.com/spider-gazelle/pars.git
Expand Down Expand Up @@ -235,7 +239,7 @@ shards:

placeos-driver:
git: https://github.com/placeos/driver.git
version: 7.2.4
version: 7.2.14

placeos-frontend-loader:
git: https://github.com/placeos/frontend-loader.git
Expand Down Expand Up @@ -335,7 +339,7 @@ shards:

time-ext:
git: https://github.com/wyhaines/time-ext.cr.git
version: 0.1.0+git.commit.175f658235fb6cdc9c804cb96da510fec27f4cd6
version: 1.0.1

timecop:
git: https://github.com/crystal-community/timecop.cr.git
Expand All @@ -347,15 +351,15 @@ shards:

tracer:
git: https://github.com/wyhaines/tracer.cr.git
version: 0.3.1
version: 0.3.2

ulid: # Overridden
git: https://github.com/place-labs/ulid.git
version: 0.1.3+git.commit.0bb8d5d4bee4168acfac2630ce51ce4706253688

upload-signer:
git: https://github.com/spider-gazelle/upload-signer.git
version: 0.1.0+git.commit.4c7baf3fc72ca15035c827e16f2c8a15b5f39246
version: 0.2.0+git.commit.fdf8a1b2886006777efd01d69450c2028e0cf21e

webmock:
git: https://github.com/manastech/webmock.cr.git
Expand Down
109 changes: 105 additions & 4 deletions spec/controllers/notifications_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module PlaceOS::Api
result.status_code.should eq 202
end

it "should receive valid payload when google sends change notification" do
it "should receive valid payload when google sends change notification to unscoped destination" do
PlaceOS::Model::Authority.find_by_domain("localhost").not_nil!
subscription_channel = "4ba78bf0-6a47-11e2-bcfd-0800200c9a66/event"

Expand Down Expand Up @@ -63,6 +63,50 @@ module PlaceOS::Api
subs.terminate
end
end

it "should receive valid payload when google sends change notification to scoped destination" do
authority = PlaceOS::Model::Authority.find_by_domain("localhost").not_nil!
subscription_channel = "#{authority.id}/4ba78bf0-6a47-11e2-bcfd-0800200c9a66/event"

channel = Channel(String).new
subs = PlaceOS::Driver::Subscriptions.new

_subscription = subs.channel subscription_channel do |_, message|
channel.send(message)
end

result = client.post("#{PushNotifications.base_route}/google", headers: HTTP::Headers{
"Host" => "localhost",
"Content-Type" => "application/json",
"Content-Length" => "0",
"X-Goog-Channel-ID" => "4ba78bf0-6a47-11e2-bcfd-0800200c9a66",
"X-Goog-Channel-Token" => "398348u3tu83ut8uu38",
"X-Goog-Channel-Expiration" => "Fri, 26 May 2023 01:13:52 GMT",
"X-Goog-Resource-ID" => "ret08u3rv24htgh289g",
"X-Goog-Resource-URI" => "https://www.googleapis.com/calendar/v3/calendars/[email protected]/events",
"X-Goog-Resource-State" => "exists",
"X-Goog-Message-Number" => "1",
})
result.status_code.should eq 202

begin
select
when message = channel.receive
{
"event_type": "updated",
"resource_id": "ret08u3rv24htgh289g",
"resource_uri": "https://www.googleapis.com/calendar/v3/calendars/[email protected]/events",
"subscription_id": "4ba78bf0-6a47-11e2-bcfd-0800200c9a66",
"client_secret": "398348u3tu83ut8uu38",
"expiration_time": 1685063632,
}.to_json.should eq(message)
when timeout 2.seconds
raise "timeout"
end
ensure
subs.terminate
end
end
end

describe "microsoft push notifications" do
Expand All @@ -78,7 +122,64 @@ module PlaceOS::Api
result.body.should eq(token)
end

it "should receive valid payload when microsoft sends change notification" do
it "should receive valid payload when microsoft sends change notification on scoped channel" do
authority = PlaceOS::Model::Authority.find_by_domain("localhost").not_nil!
subscription_channel = "#{authority.id}/f37536ac-b308-4bc7-b239-b2b51cd2ff24/event"

channel = Channel(String).new
subs = PlaceOS::Driver::Subscriptions.new

_subscription = subs.channel subscription_channel do |_, message|
channel.send(message)
end

payload = <<-'JSON'
{
"value": [
{
"subscriptionId": "f37536ac-b308-4bc7-b239-b2b51cd2ff24",
"subscriptionExpirationDateTime": "2023-05-26T23:29:18.2277768+00:00",
"changeType": "created",
"resource": "Users/2189c720-90d5-44ff-818b-fe585706ee90/Events/AAMkADlhNjJjN2M1LTJiYWUtNGVhMS04ODEzLTRjNDlmYmZkYWMyYQBGAAAAAAA2241OoLZoSZGqNr4MvSZJBwAXxlVK8zI-TZLFIn9D86hXAAAAAAENAAAXxlVK8zI-TZLFIn9D86hXAAAECHE1AAA=",
"resourceData": {
"@odata.type": "#Microsoft.Graph.Event",
"@odata.id": "Users/2189c720-90d5-44ff-818b-fe585706ee90/Events/AAMkADlhNjJjN2M1LTJiYWUtNGVhMS04ODEzLTRjNDlmYmZkYWMyYQBGAAAAAAA2241OoLZoSZGqNr4MvSZJBwAXxlVK8zI-TZLFIn9D86hXAAAAAAENAAAXxlVK8zI-TZLFIn9D86hXAAAECHE1AAA=",
"@odata.etag": "W/\"DwAAABYAAAAXxlVK8zI/TZLFIn9D86hXAAAEB/jr\"",
"id": "AAMkADlhNjJjN2M1LTJiYWUtNGVhMS04ODEzLTRjNDlmYmZkYWMyYQBGAAAAAAA2241OoLZoSZGqNr4MvSZJBwAXxlVK8zI-TZLFIn9D86hXAAAAAAENAAAXxlVK8zI-TZLFIn9D86hXAAAECHE1AAA="
},
"clientState": "secretClientState",
"tenantId": "7f1d0cb7-93b9-405a-8dad-c21703b7af18"
}
]
}
JSON
result = client.post("#{PushNotifications.base_route}/office365", body: payload, headers: HTTP::Headers{
"Host" => "localhost",
"Content-Type" => "application/json",
})

result.status_code.should eq 202

begin
select
when message = channel.receive
{
"event_type": "created",
"resource_id": "AAMkADlhNjJjN2M1LTJiYWUtNGVhMS04ODEzLTRjNDlmYmZkYWMyYQBGAAAAAAA2241OoLZoSZGqNr4MvSZJBwAXxlVK8zI-TZLFIn9D86hXAAAAAAENAAAXxlVK8zI-TZLFIn9D86hXAAAECHE1AAA=",
"resource_uri": "Users/2189c720-90d5-44ff-818b-fe585706ee90/Events/AAMkADlhNjJjN2M1LTJiYWUtNGVhMS04ODEzLTRjNDlmYmZkYWMyYQBGAAAAAAA2241OoLZoSZGqNr4MvSZJBwAXxlVK8zI-TZLFIn9D86hXAAAAAAENAAAXxlVK8zI-TZLFIn9D86hXAAAECHE1AAA=",
"subscription_id": "f37536ac-b308-4bc7-b239-b2b51cd2ff24",
"client_secret": "secretClientState",
"expiration_time": 1685143758,
}.to_json.should eq(message)
when timeout 2.seconds
raise "timeout"
end
ensure
subs.terminate
end
end

it "should receive valid payload when microsoft sends change notification on unscoped channel" do
PlaceOS::Model::Authority.find_by_domain("localhost").not_nil!
subscription_channel = "f37536ac-b308-4bc7-b239-b2b51cd2ff24/event"

Expand Down Expand Up @@ -136,8 +237,8 @@ module PlaceOS::Api
end

it "should receive valid payload when microsoft sends lifecycle notification" do
PlaceOS::Model::Authority.find_by_domain("localhost").not_nil!
subscription_channel = "f37536ac-b308-4bc7-b239-b2b51cd2ff24/event"
authority = PlaceOS::Model::Authority.find_by_domain("localhost").not_nil!
subscription_channel = "#{authority.id}/f37536ac-b308-4bc7-b239-b2b51cd2ff24/event"

channel = Channel(String).new
subs = PlaceOS::Driver::Subscriptions.new
Expand Down
38 changes: 33 additions & 5 deletions spec/controllers/root_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,34 @@ module PlaceOS::Api
end

describe "POST /signal" do
it "writes an arbitrary payload to a redis subscription" do
it "writes an arbitrary payload to a redis subscription on scoped channel" do
user, headers = Spec::Authentication.authenticated
subscription_channel = "#{user.authority.as(Model::Authority).id}/test"
channel = Channel(String).new
subs = PlaceOS::Driver::Subscriptions.new

_subscription = subs.channel subscription_channel do |_, message|
channel.send(message)
end

params = HTTP::Params{"channel" => "test"}
result = client.post(File.join(Root.base_route, "signal?#{params}"), body: "hello", headers: headers)
result.status_code.should eq 200

begin
select
when message = channel.receive
message.should eq "hello"
when timeout 2.seconds
raise "timeout"
end
ensure
subs.terminate
end
end

it "writes an arbitrary payload to a redis subscription on un-scoped channel" do
_, headers = Spec::Authentication.authenticated
subscription_channel = "test"
channel = Channel(String).new
subs = PlaceOS::Driver::Subscriptions.new
Expand All @@ -62,7 +89,7 @@ module PlaceOS::Api
end

params = HTTP::Params{"channel" => subscription_channel}
result = client.post(File.join(Root.base_route, "signal?#{params}"), body: "hello", headers: Spec::Authentication.headers)
result = client.post(File.join(Root.base_route, "signal?#{params}"), body: "hello", headers: headers)
result.status_code.should eq 200

begin
Expand All @@ -83,19 +110,20 @@ module PlaceOS::Api
end

context "guest users" do
_, guest_header = Spec::Authentication.authentication(sys_admin: false, support: false, scope: [PlaceOS::Model::UserJWT::Scope::GUEST])

it "prevented access to non-guest channels " do
_, guest_header = Spec::Authentication.authentication(sys_admin: false, support: false, scope: [PlaceOS::Model::UserJWT::Scope::GUEST])

result = client.post(File.join(Root.base_route, "signal?channel=dummy"), body: "hello", headers: guest_header)
result.status_code.should eq 403
end

it "allowed access to guest channels" do
guest, guest_header = Spec::Authentication.authentication(sys_admin: false, support: false, scope: [PlaceOS::Model::UserJWT::Scope::GUEST])
subscription_channel = "/guest/dummy"
channel = Channel(String).new
subs = PlaceOS::Driver::Subscriptions.new

_subscription = subs.channel subscription_channel do |_, message|
_subscription = subs.channel "#{guest.authority.as(Model::Authority).id}#{subscription_channel}" do |_, message|
channel.send(message)
end

Expand Down
Loading
Loading