Skip to content

Commit

Permalink
Add test code for new connect error
Browse files Browse the repository at this point in the history
Co-authored-by: Yourim Cha <chacha912@users.noreply.github.com>
Co-authored-by: Youngteac Hong <susukang98@gmail.com>
  • Loading branch information
3 people committed Jan 3, 2024
1 parent fc56c49 commit f85034a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
9 changes: 6 additions & 3 deletions server/rpc/interceptors/admin_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ import (
"github.com/yorkie-team/yorkie/server/users"
)

// ErrUnauthenticated is returned when authentication is failed.
var ErrUnauthenticated = errors.New("authorization is not provided")

// AdminAuthInterceptor is an interceptor for authentication.
type AdminAuthInterceptor struct {
backend *backend.Backend
Expand Down Expand Up @@ -155,17 +158,17 @@ func (i *AdminAuthInterceptor) authenticate(
) (*types.User, error) {
authorization := header.Get(types.AuthorizationKey)
if authorization == "" {
return nil, connect.NewError(connect.CodeUnauthenticated, errors.New("authorization is not provided"))
return nil, connect.NewError(connect.CodeUnauthenticated, ErrUnauthenticated)
}

claims, err := i.tokenManager.Verify(authorization)
if err != nil {
return nil, connect.NewError(connect.CodeUnauthenticated, errors.New("authorization is invalid"))
return nil, connect.NewError(connect.CodeUnauthenticated, ErrUnauthenticated)
}

user, err := users.GetUser(ctx, i.backend, claims.Username)
if err != nil {
return nil, connect.NewError(connect.CodeUnauthenticated, errors.New("authorization is invalid"))
return nil, connect.NewError(connect.CodeUnauthenticated, ErrUnauthenticated)
}

return user, nil
Expand Down
13 changes: 13 additions & 0 deletions test/integration/admin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,17 @@ func TestAdmin(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, document.StatusDetached, doc.Status())
})

t.Run("unauthentication test", func(t *testing.T) {
// 01. try to call admin API without token.
adminCli2, err := admin.Dial(defaultServer.RPCAddr(), admin.WithInsecure(true))
assert.NoError(t, err)
defer func() {
adminCli2.Close()
}()
_, err = adminCli2.GetProject(ctx, "default")

// 02. server should return unauthenticated error.
assert.Equal(t, connect.CodeUnauthenticated, connect.CodeOf(err))
})
}

1 comment on commit f85034a

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Go Benchmark

Benchmark suite Current: f85034a Previous: fc56c49 Ratio
BenchmarkDocument/constructor_test - ns/op 1395 ns/op 1539 ns/op 0.91
BenchmarkDocument/constructor_test - B/op 1208 B/op 1208 B/op 1
BenchmarkDocument/constructor_test - allocs/op 20 allocs/op 20 allocs/op 1
BenchmarkDocument/status_test - ns/op 780.9 ns/op 775.3 ns/op 1.01
BenchmarkDocument/status_test - B/op 1176 B/op 1176 B/op 1
BenchmarkDocument/status_test - allocs/op 18 allocs/op 18 allocs/op 1
BenchmarkDocument/equals_test - ns/op 7102 ns/op 7066 ns/op 1.01
BenchmarkDocument/equals_test - B/op 6913 B/op 6913 B/op 1
BenchmarkDocument/equals_test - allocs/op 120 allocs/op 120 allocs/op 1
BenchmarkDocument/nested_update_test - ns/op 16208 ns/op 15997 ns/op 1.01
BenchmarkDocument/nested_update_test - B/op 11963 B/op 11963 B/op 1
BenchmarkDocument/nested_update_test - allocs/op 254 allocs/op 254 allocs/op 1
BenchmarkDocument/delete_test - ns/op 21941 ns/op 21807 ns/op 1.01
BenchmarkDocument/delete_test - B/op 15188 B/op 15187 B/op 1.00
BenchmarkDocument/delete_test - allocs/op 333 allocs/op 333 allocs/op 1
BenchmarkDocument/object_test - ns/op 8283 ns/op 8315 ns/op 1.00
BenchmarkDocument/object_test - B/op 6721 B/op 6721 B/op 1
BenchmarkDocument/object_test - allocs/op 116 allocs/op 116 allocs/op 1
BenchmarkDocument/array_test - ns/op 31078 ns/op 28511 ns/op 1.09
BenchmarkDocument/array_test - B/op 11819 B/op 11819 B/op 1
BenchmarkDocument/array_test - allocs/op 270 allocs/op 270 allocs/op 1
BenchmarkDocument/text_test - ns/op 30704 ns/op 30499 ns/op 1.01
BenchmarkDocument/text_test - B/op 14795 B/op 14795 B/op 1
BenchmarkDocument/text_test - allocs/op 468 allocs/op 468 allocs/op 1
BenchmarkDocument/text_composition_test - ns/op 28623 ns/op 28595 ns/op 1.00
BenchmarkDocument/text_composition_test - B/op 18278 B/op 18276 B/op 1.00
BenchmarkDocument/text_composition_test - allocs/op 477 allocs/op 477 allocs/op 1
BenchmarkDocument/rich_text_test - ns/op 79795 ns/op 80099 ns/op 1.00
BenchmarkDocument/rich_text_test - B/op 38540 B/op 38540 B/op 1
BenchmarkDocument/rich_text_test - allocs/op 1147 allocs/op 1147 allocs/op 1
BenchmarkDocument/counter_test - ns/op 16622 ns/op 16525 ns/op 1.01
BenchmarkDocument/counter_test - B/op 10210 B/op 10210 B/op 1
BenchmarkDocument/counter_test - allocs/op 236 allocs/op 236 allocs/op 1
BenchmarkDocument/text_edit_gc_100 - ns/op 2888298 ns/op 2878354 ns/op 1.00
BenchmarkDocument/text_edit_gc_100 - B/op 1655474 B/op 1655269 B/op 1.00
BenchmarkDocument/text_edit_gc_100 - allocs/op 17094 allocs/op 17092 allocs/op 1.00
BenchmarkDocument/text_edit_gc_1000 - ns/op 231602165 ns/op 230228767 ns/op 1.01
BenchmarkDocument/text_edit_gc_1000 - B/op 144349672 B/op 144351169 B/op 1.00
BenchmarkDocument/text_edit_gc_1000 - allocs/op 200918 allocs/op 200919 allocs/op 1.00
BenchmarkDocument/text_split_gc_100 - ns/op 3375095 ns/op 3394456 ns/op 0.99
BenchmarkDocument/text_split_gc_100 - B/op 2313699 B/op 2313494 B/op 1.00
BenchmarkDocument/text_split_gc_100 - allocs/op 16195 allocs/op 16193 allocs/op 1.00
BenchmarkDocument/text_split_gc_1000 - ns/op 292951956 ns/op 289474463 ns/op 1.01
BenchmarkDocument/text_split_gc_1000 - B/op 228910776 B/op 228892588 B/op 1.00
BenchmarkDocument/text_split_gc_1000 - allocs/op 204055 allocs/op 203958 allocs/op 1.00
BenchmarkDocument/text_delete_all_10000 - ns/op 10701507 ns/op 10740397 ns/op 1.00
BenchmarkDocument/text_delete_all_10000 - B/op 5810877 B/op 5810698 B/op 1.00
BenchmarkDocument/text_delete_all_10000 - allocs/op 40676 allocs/op 40676 allocs/op 1
BenchmarkDocument/text_delete_all_100000 - ns/op 179522890 ns/op 184931326 ns/op 0.97
BenchmarkDocument/text_delete_all_100000 - B/op 81912336 B/op 81903976 B/op 1.00
BenchmarkDocument/text_delete_all_100000 - allocs/op 411676 allocs/op 411649 allocs/op 1.00
BenchmarkDocument/text_100 - ns/op 219492 ns/op 221592 ns/op 0.99
BenchmarkDocument/text_100 - B/op 118483 B/op 118483 B/op 1
BenchmarkDocument/text_100 - allocs/op 5080 allocs/op 5080 allocs/op 1
BenchmarkDocument/text_1000 - ns/op 2390826 ns/op 2467395 ns/op 0.97
BenchmarkDocument/text_1000 - B/op 1153070 B/op 1153070 B/op 1
BenchmarkDocument/text_1000 - allocs/op 50084 allocs/op 50084 allocs/op 1
BenchmarkDocument/array_1000 - ns/op 1180748 ns/op 1206674 ns/op 0.98
BenchmarkDocument/array_1000 - B/op 1091233 B/op 1091214 B/op 1.00
BenchmarkDocument/array_1000 - allocs/op 11825 allocs/op 11825 allocs/op 1
BenchmarkDocument/array_10000 - ns/op 13030953 ns/op 13059643 ns/op 1.00
BenchmarkDocument/array_10000 - B/op 9798670 B/op 9799712 B/op 1.00
BenchmarkDocument/array_10000 - allocs/op 120285 allocs/op 120289 allocs/op 1.00
BenchmarkDocument/array_gc_100 - ns/op 143058 ns/op 147189 ns/op 0.97
BenchmarkDocument/array_gc_100 - B/op 132499 B/op 132494 B/op 1.00
BenchmarkDocument/array_gc_100 - allocs/op 1249 allocs/op 1248 allocs/op 1.00
BenchmarkDocument/array_gc_1000 - ns/op 1366412 ns/op 1391924 ns/op 0.98
BenchmarkDocument/array_gc_1000 - B/op 1158928 B/op 1159019 B/op 1.00
BenchmarkDocument/array_gc_1000 - allocs/op 12865 allocs/op 12865 allocs/op 1
BenchmarkDocument/counter_1000 - ns/op 197307 ns/op 200439 ns/op 0.98
BenchmarkDocument/counter_1000 - B/op 192853 B/op 192853 B/op 1
BenchmarkDocument/counter_1000 - allocs/op 5765 allocs/op 5765 allocs/op 1
BenchmarkDocument/counter_10000 - ns/op 2133911 ns/op 2165762 ns/op 0.99
BenchmarkDocument/counter_10000 - B/op 2087769 B/op 2087783 B/op 1.00
BenchmarkDocument/counter_10000 - allocs/op 59772 allocs/op 59772 allocs/op 1
BenchmarkDocument/object_1000 - ns/op 1347369 ns/op 1342137 ns/op 1.00
BenchmarkDocument/object_1000 - B/op 1428031 B/op 1427955 B/op 1.00
BenchmarkDocument/object_1000 - allocs/op 9845 allocs/op 9845 allocs/op 1
BenchmarkDocument/object_10000 - ns/op 14854892 ns/op 14616037 ns/op 1.02
BenchmarkDocument/object_10000 - B/op 12166100 B/op 12165301 B/op 1.00
BenchmarkDocument/object_10000 - allocs/op 100560 allocs/op 100556 allocs/op 1.00
BenchmarkDocument/tree_100 - ns/op 1027584 ns/op 1018336 ns/op 1.01
BenchmarkDocument/tree_100 - B/op 943675 B/op 943676 B/op 1.00
BenchmarkDocument/tree_100 - allocs/op 6099 allocs/op 6099 allocs/op 1
BenchmarkDocument/tree_1000 - ns/op 75721341 ns/op 73572042 ns/op 1.03
BenchmarkDocument/tree_1000 - B/op 86460291 B/op 86460440 B/op 1.00
BenchmarkDocument/tree_1000 - allocs/op 60112 allocs/op 60114 allocs/op 1.00
BenchmarkDocument/tree_10000 - ns/op 9317246479 ns/op 9342953138 ns/op 1.00
BenchmarkDocument/tree_10000 - B/op 8580983320 B/op 8580980632 B/op 1.00
BenchmarkDocument/tree_10000 - allocs/op 600241 allocs/op 600228 allocs/op 1.00
BenchmarkDocument/tree_delete_all_1000 - ns/op 71648989 ns/op 73961264 ns/op 0.97
BenchmarkDocument/tree_delete_all_1000 - B/op 86990577 B/op 86990525 B/op 1.00
BenchmarkDocument/tree_delete_all_1000 - allocs/op 67750 allocs/op 67752 allocs/op 1.00
BenchmarkDocument/tree_edit_gc_100 - ns/op 3606697 ns/op 3689933 ns/op 0.98
BenchmarkDocument/tree_edit_gc_100 - B/op 4120927 B/op 4120968 B/op 1.00
BenchmarkDocument/tree_edit_gc_100 - allocs/op 14356 allocs/op 14356 allocs/op 1
BenchmarkDocument/tree_edit_gc_1000 - ns/op 297907580 ns/op 304660268 ns/op 0.98
BenchmarkDocument/tree_edit_gc_1000 - B/op 383466926 B/op 383466150 B/op 1.00
BenchmarkDocument/tree_edit_gc_1000 - allocs/op 145399 allocs/op 145409 allocs/op 1.00
BenchmarkDocument/tree_split_gc_100 - ns/op 2425300 ns/op 2446825 ns/op 0.99
BenchmarkDocument/tree_split_gc_100 - B/op 2386802 B/op 2386847 B/op 1.00
BenchmarkDocument/tree_split_gc_100 - allocs/op 10341 allocs/op 10341 allocs/op 1
BenchmarkDocument/tree_split_gc_1000 - ns/op 179341958 ns/op 180180666 ns/op 1.00
BenchmarkDocument/tree_split_gc_1000 - B/op 221990900 B/op 221989840 B/op 1.00
BenchmarkDocument/tree_split_gc_1000 - allocs/op 112252 allocs/op 112245 allocs/op 1.00
BenchmarkRPC/client_to_server - ns/op 351908721 ns/op 361275305 ns/op 0.97
BenchmarkRPC/client_to_server - B/op 18071440 B/op 18162360 B/op 0.99
BenchmarkRPC/client_to_server - allocs/op 166881 allocs/op 166902 allocs/op 1.00
BenchmarkRPC/client_to_client_via_server - ns/op 601476004 ns/op 607584738 ns/op 0.99
BenchmarkRPC/client_to_client_via_server - B/op 32096184 B/op 32053132 B/op 1.00
BenchmarkRPC/client_to_client_via_server - allocs/op 312445 allocs/op 312420 allocs/op 1.00
BenchmarkRPC/attach_large_document - ns/op 1319726647 ns/op 1209824712 ns/op 1.09
BenchmarkRPC/attach_large_document - B/op 1877906480 B/op 1878731824 B/op 1.00
BenchmarkRPC/attach_large_document - allocs/op 7463 allocs/op 7545 allocs/op 0.99
BenchmarkRPC/adminCli_to_server - ns/op 533060570 ns/op 536551048 ns/op 0.99
BenchmarkRPC/adminCli_to_server - B/op 35998592 B/op 36393252 B/op 0.99
BenchmarkRPC/adminCli_to_server - allocs/op 289696 allocs/op 289649 allocs/op 1.00
BenchmarkLocker - ns/op 64.03 ns/op 64.73 ns/op 0.99
BenchmarkLocker - B/op 16 B/op 16 B/op 1
BenchmarkLocker - allocs/op 1 allocs/op 1 allocs/op 1
BenchmarkLockerParallel - ns/op 38.37 ns/op 38.49 ns/op 1.00
BenchmarkLockerParallel - B/op 0 B/op 0 B/op NaN
BenchmarkLockerParallel - allocs/op 0 allocs/op 0 allocs/op NaN
BenchmarkLockerMoreKeys - ns/op 142.3 ns/op 138.8 ns/op 1.03
BenchmarkLockerMoreKeys - B/op 15 B/op 15 B/op 1
BenchmarkLockerMoreKeys - allocs/op 0 allocs/op 0 allocs/op NaN
BenchmarkChange/Push_10_Changes - ns/op 3728165 ns/op 3794353 ns/op 0.98
BenchmarkChange/Push_10_Changes - B/op 126738 B/op 125827 B/op 1.01
BenchmarkChange/Push_10_Changes - allocs/op 1254 allocs/op 1253 allocs/op 1.00
BenchmarkChange/Push_100_Changes - ns/op 13790618 ns/op 14230236 ns/op 0.97
BenchmarkChange/Push_100_Changes - B/op 645990 B/op 642170 B/op 1.01
BenchmarkChange/Push_100_Changes - allocs/op 6539 allocs/op 6538 allocs/op 1.00
BenchmarkChange/Push_1000_Changes - ns/op 110634000 ns/op 115168634 ns/op 0.96
BenchmarkChange/Push_1000_Changes - B/op 6134578 B/op 6152199 B/op 1.00
BenchmarkChange/Push_1000_Changes - allocs/op 62158 allocs/op 62159 allocs/op 1.00
BenchmarkChange/Pull_10_Changes - ns/op 2816965 ns/op 2827802 ns/op 1.00
BenchmarkChange/Pull_10_Changes - B/op 101057 B/op 100467 B/op 1.01
BenchmarkChange/Pull_10_Changes - allocs/op 951 allocs/op 951 allocs/op 1
BenchmarkChange/Pull_100_Changes - ns/op 4287676 ns/op 4319575 ns/op 0.99
BenchmarkChange/Pull_100_Changes - B/op 258800 B/op 257826 B/op 1.00
BenchmarkChange/Pull_100_Changes - allocs/op 3155 allocs/op 3154 allocs/op 1.00
BenchmarkChange/Pull_1000_Changes - ns/op 8281325 ns/op 8308723 ns/op 1.00
BenchmarkChange/Pull_1000_Changes - B/op 1396887 B/op 1394641 B/op 1.00
BenchmarkChange/Pull_1000_Changes - allocs/op 26874 allocs/op 26873 allocs/op 1.00
BenchmarkSnapshot/Push_3KB_snapshot - ns/op 16430630 ns/op 16919040 ns/op 0.97
BenchmarkSnapshot/Push_3KB_snapshot - B/op 815981 B/op 811205 B/op 1.01
BenchmarkSnapshot/Push_3KB_snapshot - allocs/op 6541 allocs/op 6541 allocs/op 1
BenchmarkSnapshot/Push_30KB_snapshot - ns/op 115639701 ns/op 118888206 ns/op 0.97
BenchmarkSnapshot/Push_30KB_snapshot - B/op 6230179 B/op 6233262 B/op 1.00
BenchmarkSnapshot/Push_30KB_snapshot - allocs/op 62162 allocs/op 62159 allocs/op 1.00
BenchmarkSnapshot/Pull_3KB_snapshot - ns/op 6612570 ns/op 6527254 ns/op 1.01
BenchmarkSnapshot/Pull_3KB_snapshot - B/op 907069 B/op 905404 B/op 1.00
BenchmarkSnapshot/Pull_3KB_snapshot - allocs/op 14884 allocs/op 14879 allocs/op 1.00
BenchmarkSnapshot/Pull_30KB_snapshot - ns/op 14670043 ns/op 14597665 ns/op 1.00
BenchmarkSnapshot/Pull_30KB_snapshot - B/op 6979414 B/op 6978064 B/op 1.00
BenchmarkSnapshot/Pull_30KB_snapshot - allocs/op 144140 allocs/op 144138 allocs/op 1.00
BenchmarkSync/memory_sync_10_test - ns/op 6661 ns/op 6838 ns/op 0.97
BenchmarkSync/memory_sync_10_test - B/op 1286 B/op 1286 B/op 1
BenchmarkSync/memory_sync_10_test - allocs/op 38 allocs/op 38 allocs/op 1
BenchmarkSync/memory_sync_100_test - ns/op 50765 ns/op 51435 ns/op 0.99
BenchmarkSync/memory_sync_100_test - B/op 8659 B/op 8649 B/op 1.00
BenchmarkSync/memory_sync_100_test - allocs/op 274 allocs/op 273 allocs/op 1.00
BenchmarkSync/memory_sync_1000_test - ns/op 584946 ns/op 592684 ns/op 0.99
BenchmarkSync/memory_sync_1000_test - B/op 74835 B/op 74389 B/op 1.01
BenchmarkSync/memory_sync_1000_test - allocs/op 2138 allocs/op 2111 allocs/op 1.01
BenchmarkSync/memory_sync_10000_test - ns/op 7033997 ns/op 7083029 ns/op 0.99
BenchmarkSync/memory_sync_10000_test - B/op 764805 B/op 762291 B/op 1.00
BenchmarkSync/memory_sync_10000_test - allocs/op 20665 allocs/op 20542 allocs/op 1.01
BenchmarkTextEditing - ns/op 19113748422 ns/op 18923499280 ns/op 1.01
BenchmarkTextEditing - B/op 9037840216 B/op 9038821944 B/op 1.00
BenchmarkTextEditing - allocs/op 19922783 allocs/op 19924308 allocs/op 1.00

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.