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

Handle a missing CountDetails node in the returned responses for Get<Entity>RuntimeProperties #18213

Merged
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
5 changes: 5 additions & 0 deletions sdk/messaging/azservicebus/admin/admin_client_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package admin

import (
"context"
"errors"
"net/http"
"time"

Expand Down Expand Up @@ -430,6 +431,10 @@ func newQueueItem(env *atom.QueueEnvelope) (*QueueItem, error) {
func newQueueRuntimePropertiesItem(env *atom.QueueEnvelope) (*QueueRuntimePropertiesItem, error) {
desc := env.Content.QueueDescription

if desc.CountDetails == nil {
return nil, errors.New("invalid queue runtime properties: no CountDetails element")
}

qrt := &QueueRuntimeProperties{
SizeInBytes: int64OrZero(desc.SizeInBytes),
TotalMessageCount: int64OrZero(desc.MessageCount),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package admin

import (
"context"
"errors"
"fmt"
"net/http"
"time"
Expand Down Expand Up @@ -415,6 +416,10 @@ func newSubscriptionItem(env *atom.SubscriptionEnvelope, topicName string) (*Sub
func newSubscriptionRuntimePropertiesItem(env *atom.SubscriptionEnvelope, topicName string) (*SubscriptionRuntimePropertiesItem, error) {
desc := env.Content.SubscriptionDescription

if desc.CountDetails == nil {
return nil, errors.New("invalid subscription runtime properties: no CountDetails element")
}

rtp := SubscriptionRuntimeProperties{
TotalMessageCount: *desc.MessageCount,
ActiveMessageCount: *desc.CountDetails.ActiveMessageCount,
Expand Down
14 changes: 14 additions & 0 deletions sdk/messaging/azservicebus/admin/admin_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1750,3 +1750,17 @@ func createAuthorizationRulesForTest(t *testing.T) []AuthorizationRule {
},
}
}

func TestATOMNoCountDetails(t *testing.T) {
subRP, err := newSubscriptionRuntimePropertiesItem(&atom.SubscriptionEnvelope{Content: &atom.SubscriptionContent{}}, "topic")
require.Nil(t, subRP)
require.Error(t, err, "invalid subscription runtime properties: no CountDetails element")

qRP, err := newQueueRuntimePropertiesItem(&atom.QueueEnvelope{Content: &atom.QueueContent{}})
require.Nil(t, qRP)
require.Error(t, err, "invalid queue runtime properties: no CountDetails element")

tRP, err := newTopicRuntimePropertiesItem(&atom.TopicEnvelope{Content: &atom.TopicContent{}})
require.Nil(t, tRP)
require.Error(t, err, "invalid topic runtime properties: no CountDetails element")
}
5 changes: 5 additions & 0 deletions sdk/messaging/azservicebus/admin/admin_client_topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package admin

import (
"context"
"errors"
"net/http"
"time"

Expand Down Expand Up @@ -386,6 +387,10 @@ func newTopicItem(te *atom.TopicEnvelope) (*TopicItem, error) {
func newTopicRuntimePropertiesItem(env *atom.TopicEnvelope) (*TopicRuntimePropertiesItem, error) {
desc := env.Content.TopicDescription

if desc.CountDetails == nil {
return nil, errors.New("invalid topic runtime properties: no CountDetails element")
}

props := &TopicRuntimeProperties{
SizeInBytes: int64OrZero(desc.SizeInBytes),
ScheduledMessageCount: int32OrZero(desc.CountDetails.ScheduledMessageCount),
Expand Down
6 changes: 3 additions & 3 deletions sdk/messaging/azservicebus/internal/atom/converters.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func WrapWithQueueEnvelope(qd *QueueDescription, tokenProvider auth.TokenProvide
Entry: &Entry{
AtomSchema: atomSchema,
},
Content: &queueContent{
Content: &QueueContent{
Type: applicationXML,
QueueDescription: *qd,
},
Expand All @@ -31,7 +31,7 @@ func WrapWithTopicEnvelope(td *TopicDescription) *TopicEnvelope {
Entry: &Entry{
AtomSchema: atomSchema,
},
Content: &topicContent{
Content: &TopicContent{
Type: applicationXML,
TopicDescription: *td,
},
Expand All @@ -45,7 +45,7 @@ func WrapWithSubscriptionEnvelope(sd *SubscriptionDescription) *SubscriptionEnve
Entry: &Entry{
AtomSchema: atomSchema,
},
Content: &subscriptionContent{
Content: &SubscriptionContent{
Type: applicationXML,
SubscriptionDescription: *sd,
},
Expand Down
18 changes: 9 additions & 9 deletions sdk/messaging/azservicebus/internal/atom/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ type (
// QueueEnvelope is a specialized Queue feed entry
QueueEnvelope struct {
*Entry
Content *queueContent `xml:"content"`
Content *QueueContent `xml:"content"`
}

// queueContent is a specialized Queue body for an Atom entry
queueContent struct {
// QueueContent is a specialized Queue body for an Atom entry
QueueContent struct {
XMLName xml.Name `xml:"content"`
Type string `xml:"type,attr"`
QueueDescription QueueDescription `xml:"QueueDescription"`
Expand Down Expand Up @@ -103,11 +103,11 @@ type (
// TopicEnvelope is a specialized Topic feed entry
TopicEnvelope struct {
*Entry
Content *topicContent `xml:"content"`
Content *TopicContent `xml:"content"`
}

// topicContent is a specialized Topic body for an Atom entry
topicContent struct {
// TopicContent is a specialized Topic body for an Atom entry
TopicContent struct {
XMLName xml.Name `xml:"content"`
Type string `xml:"type,attr"`
TopicDescription TopicDescription `xml:"TopicDescription"`
Expand Down Expand Up @@ -296,11 +296,11 @@ type (
// subscriptionEntryContent is a specialized Topic feed Subscription
SubscriptionEnvelope struct {
*Entry
Content *subscriptionContent `xml:"content"`
Content *SubscriptionContent `xml:"content"`
}

// subscriptionContent is a specialized Subscription body for an Atom entry
subscriptionContent struct {
// SubscriptionContent is a specialized Subscription body for an Atom entry
SubscriptionContent struct {
XMLName xml.Name `xml:"content"`
Type string `xml:"type,attr"`
SubscriptionDescription SubscriptionDescription `xml:"SubscriptionDescription"`
Expand Down