MCPcopy Create free account
hub / github.com/TheThingsNetwork/lorawan-stack / TestRequire

Function TestRequire

pkg/auth/rights/require_test.go:114–223  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

112}
113
114func TestRequire(t *testing.T) {
115 t.Parallel()
116 a, ctx := test.New(t)
117
118 a.So(func() {
119 _ = rights.RequireUniversal(ctx, ttnpb.Right_RIGHT_SEND_INVITES)
120 }, should.Panic)
121 a.So(func() {
122 _ = rights.RequireIsAdmin(ctx)
123 }, should.Panic)
124 a.So(func() {
125 _ = rights.RequireApplication(ctx, &ttnpb.ApplicationIdentifiers{}, ttnpb.Right_RIGHT_APPLICATION_INFO)
126 }, should.Panic)
127 a.So(func() {
128 _ = rights.RequireClient(ctx, &ttnpb.ClientIdentifiers{}, ttnpb.Right_RIGHT_CLIENT_INFO)
129 }, should.Panic)
130 a.So(func() {
131 _ = rights.RequireGateway(ctx, &ttnpb.GatewayIdentifiers{}, ttnpb.Right_RIGHT_GATEWAY_INFO)
132 }, should.Panic)
133 a.So(func() {
134 _ = rights.RequireOrganization(ctx, &ttnpb.OrganizationIdentifiers{}, ttnpb.Right_RIGHT_ORGANIZATION_INFO)
135 }, should.Panic)
136 a.So(func() {
137 _ = rights.RequireUser(ctx, &ttnpb.UserIdentifiers{}, ttnpb.Right_RIGHT_USER_INFO)
138 }, should.Panic)
139
140 var (
141 fooCtx = ctx
142 fooID = "foo"
143 )
144 fooCtx = rights.NewContext(fooCtx, &rights.Rights{
145 ApplicationRights: *rights.NewMap(map[string]*ttnpb.Rights{
146 unique.ID(fooCtx, &ttnpb.ApplicationIdentifiers{
147 ApplicationId: fooID,
148 }): ttnpb.RightsFrom(ttnpb.Right_RIGHT_APPLICATION_INFO),
149 }),
150 ClientRights: *rights.NewMap(map[string]*ttnpb.Rights{
151 unique.ID(fooCtx, &ttnpb.ClientIdentifiers{
152 ClientId: fooID,
153 }): ttnpb.RightsFrom(ttnpb.Right_RIGHT_CLIENT_INFO),
154 }),
155 GatewayRights: *rights.NewMap(map[string]*ttnpb.Rights{
156 unique.ID(fooCtx, &ttnpb.GatewayIdentifiers{
157 GatewayId: fooID,
158 }): ttnpb.RightsFrom(ttnpb.Right_RIGHT_GATEWAY_INFO),
159 }),
160 OrganizationRights: *rights.NewMap(map[string]*ttnpb.Rights{
161 unique.ID(fooCtx, &ttnpb.OrganizationIdentifiers{
162 OrganizationId: fooID,
163 }): ttnpb.RightsFrom(ttnpb.Right_RIGHT_ORGANIZATION_INFO),
164 }),
165 UserRights: *rights.NewMap(map[string]*ttnpb.Rights{
166 unique.ID(fooCtx, &ttnpb.UserIdentifiers{
167 UserId: fooID,
168 }): ttnpb.RightsFrom(ttnpb.Right_RIGHT_USER_INFO),
169 }),
170 })
171 fooCtx = rights.NewContextWithAuthInfo(fooCtx, &ttnpb.AuthInfoResponse{

Callers

nothing calls this directly

Calls 15

NewFunction · 0.92
RequireUniversalFunction · 0.92
RequireIsAdminFunction · 0.92
RequireApplicationFunction · 0.92
RequireClientFunction · 0.92
RequireGatewayFunction · 0.92
RequireOrganizationFunction · 0.92
RequireUserFunction · 0.92
NewContextFunction · 0.92
NewMapFunction · 0.92
IDFunction · 0.92
RightsFromFunction · 0.92

Tested by

no test coverage detected