Skip to content

Commit 73be4b4

Browse files
Merge pull request #91 from uw-labs/fix-copy-pasta
Fix ACL copy pasta
2 parents 26edce6 + 8be1054 commit 73be4b4

File tree

3 files changed

+144
-1
lines changed

3 files changed

+144
-1
lines changed

backend/acl/sink_test.go

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package acl
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"testing"
7+
8+
"github.com/stretchr/testify/require"
9+
"github.com/uw-labs/proximo/proto"
10+
"github.com/uw-labs/substrate"
11+
)
12+
13+
func Test_FactoryConsumeOnlyClientCannotPublish(t *testing.T) {
14+
assert := require.New(t)
15+
16+
c, err := ConfigFromString(fmt.Sprintf(`
17+
default:
18+
roles: []
19+
roles:
20+
- id: "read-dogs"
21+
consume: ["dogs.*"]
22+
clients:
23+
- id: "dog-consumer"
24+
secret: "%s"
25+
roles: ["read-dogs"]`, passwordHash))
26+
27+
s := AsyncSinkFactory{
28+
Config: c,
29+
Next: backend{},
30+
}
31+
32+
ctx := createCtx("dog-consumer", password)
33+
34+
_, err = s.NewAsyncSink(ctx, &proto.StartPublishRequest{
35+
Topic: "dogs",
36+
})
37+
38+
assert.Equal(err, ErrUnauthorized)
39+
}
40+
41+
func Test_FactoryPublishOnlyClientCanPublish(t *testing.T) {
42+
assert := require.New(t)
43+
44+
c, err := ConfigFromString(fmt.Sprintf(`
45+
default:
46+
roles: []
47+
roles:
48+
- id: "write-dogs"
49+
publish: ["dogs.*"]
50+
clients:
51+
- id: "dog-publisher"
52+
secret: "%s"
53+
roles: ["write-dogs"]`, passwordHash))
54+
55+
s := AsyncSinkFactory{
56+
Config: c,
57+
Next: backend{},
58+
}
59+
60+
ctx := createCtx("dog-publisher", password)
61+
62+
_, err = s.NewAsyncSink(ctx, &proto.StartPublishRequest{
63+
Topic: "dogs",
64+
})
65+
66+
assert.NoError(err)
67+
}
68+
69+
type backend struct {
70+
}
71+
72+
func (s backend) NewAsyncSource(ctx context.Context, req *proto.StartConsumeRequest) (substrate.AsyncMessageSource, error) {
73+
return nil, nil
74+
}
75+
76+
func (s backend) NewAsyncSink(ctx context.Context, req *proto.StartPublishRequest) (substrate.AsyncMessageSink, error) {
77+
return nil, nil
78+
}

backend/acl/source.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func (s AsyncSourceFactory) NewAsyncSource(ctx context.Context, req *proto.Start
1919
return nil, err
2020
}
2121

22-
if !containsRegex(scope.Publish, req.Topic) {
22+
if !containsRegex(scope.Consume, req.Topic) {
2323
return nil, ErrUnauthorized
2424
}
2525

backend/acl/source_test.go

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package acl
2+
3+
import (
4+
"fmt"
5+
"testing"
6+
7+
"github.com/stretchr/testify/require"
8+
"github.com/uw-labs/proximo/proto"
9+
)
10+
11+
func Test_FactoryPublishOnlyClientCannotConsume(t *testing.T) {
12+
assert := require.New(t)
13+
14+
c, err := ConfigFromString(fmt.Sprintf(`
15+
default:
16+
roles: []
17+
roles:
18+
- id: "write-dogs"
19+
publish: ["dogs.*"]
20+
clients:
21+
- id: "dog-publisher"
22+
secret: "%s"
23+
roles: ["write-dogs"]`, passwordHash))
24+
25+
s := AsyncSourceFactory{
26+
Config: c,
27+
Next: backend{},
28+
}
29+
30+
ctx := createCtx("dog-publisher", password)
31+
32+
_, err = s.NewAsyncSource(ctx, &proto.StartConsumeRequest{
33+
Topic: "dogs",
34+
})
35+
36+
assert.Equal(err, ErrUnauthorized)
37+
}
38+
39+
func Test_FactoryConsumeOnlyClientCanConsume(t *testing.T) {
40+
assert := require.New(t)
41+
42+
c, err := ConfigFromString(fmt.Sprintf(`
43+
default:
44+
roles: []
45+
roles:
46+
- id: "read-dogs"
47+
consume: ["dogs.*"]
48+
clients:
49+
- id: "dog-consumer"
50+
secret: "%s"
51+
roles: ["read-dogs"]`, passwordHash))
52+
53+
s := AsyncSourceFactory{
54+
Config: c,
55+
Next: backend{},
56+
}
57+
58+
ctx := createCtx("dog-consumer", password)
59+
60+
_, err = s.NewAsyncSource(ctx, &proto.StartConsumeRequest{
61+
Topic: "dogs",
62+
})
63+
64+
assert.NoError(err)
65+
}

0 commit comments

Comments
 (0)