|
| 1 | +// Copyright 2023 Datafuse Labs. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +use std::collections::HashSet; |
| 16 | + |
| 17 | +use chrono::DateTime; |
| 18 | +use chrono::Utc; |
| 19 | +use databend_common_meta_app as mt; |
| 20 | +use databend_common_meta_app::principal::OwnershipInfo; |
| 21 | +use databend_common_meta_app::principal::OwnershipObject; |
| 22 | +use databend_common_meta_app::principal::UserGrantSet; |
| 23 | +use databend_common_meta_app::principal::UserPrivilegeType; |
| 24 | +use enumflags2::make_bitflags; |
| 25 | +use fastrace::func_name; |
| 26 | + |
| 27 | +use crate::common; |
| 28 | + |
| 29 | +#[test] |
| 30 | +fn test_decode_v161_grant_object() -> anyhow::Result<()> { |
| 31 | + let role_info_v161 = vec![ |
| 32 | + 10, 8, 114, 97, 112, 95, 114, 111, 108, 101, 18, 61, 10, 24, 10, 9, 10, 0, 160, 6, 161, 1, |
| 33 | + 168, 6, 24, 16, 128, 128, 128, 128, 8, 160, 6, 161, 1, 168, 6, 24, 10, 26, 10, 11, 106, 2, |
| 34 | + 8, 7, 160, 6, 161, 1, 168, 6, 24, 16, 128, 128, 128, 128, 4, 160, 6, 161, 1, 168, 6, 24, |
| 35 | + 160, 6, 161, 1, 168, 6, 24, 26, 23, 49, 57, 55, 48, 45, 48, 49, 45, 48, 49, 32, 48, 48, 58, |
| 36 | + 48, 48, 58, 48, 48, 32, 85, 84, 67, 34, 23, 49, 57, 55, 48, 45, 48, 49, 45, 48, 49, 32, 48, |
| 37 | + 48, 58, 48, 48, 58, 48, 48, 32, 85, 84, 67, 160, 6, 161, 1, 168, 6, 24, |
| 38 | + ]; |
| 39 | + |
| 40 | + let want = || mt::principal::RoleInfo { |
| 41 | + name: "rap_role".to_string(), |
| 42 | + comment: None, |
| 43 | + grants: UserGrantSet::new( |
| 44 | + vec![ |
| 45 | + mt::principal::GrantEntry::new( |
| 46 | + mt::principal::GrantObject::Global, |
| 47 | + make_bitflags!(UserPrivilegeType::{CreateRowAccessPolicy}), |
| 48 | + ), |
| 49 | + mt::principal::GrantEntry::new( |
| 50 | + mt::principal::GrantObject::RowAccessPolicy(7), |
| 51 | + make_bitflags!(UserPrivilegeType::{ApplyRowAccessPolicy}), |
| 52 | + ), |
| 53 | + ], |
| 54 | + HashSet::new(), |
| 55 | + ), |
| 56 | + created_on: DateTime::<Utc>::default(), |
| 57 | + update_on: DateTime::<Utc>::default(), |
| 58 | + }; |
| 59 | + |
| 60 | + common::test_pb_from_to(func_name!(), want())?; |
| 61 | + common::test_load_old(func_name!(), role_info_v161.as_slice(), 161, want())?; |
| 62 | + |
| 63 | + Ok(()) |
| 64 | +} |
| 65 | + |
| 66 | +#[test] |
| 67 | +fn test_decode_v161_row_access_policy_ownership() -> anyhow::Result<()> { |
| 68 | + let ownership_info_v161 = vec![ |
| 69 | + 10, 10, 111, 119, 110, 101, 114, 95, 114, 111, 108, 101, 18, 11, 82, 2, 8, 42, 160, 6, 161, |
| 70 | + 1, 168, 6, 24, 160, 6, 161, 1, 168, 6, 24, |
| 71 | + ]; |
| 72 | + |
| 73 | + let want = || OwnershipInfo { |
| 74 | + role: "owner_role".to_string(), |
| 75 | + object: OwnershipObject::RowAccessPolicy { policy_id: 42 }, |
| 76 | + }; |
| 77 | + |
| 78 | + common::test_pb_from_to(func_name!(), want())?; |
| 79 | + common::test_load_old(func_name!(), ownership_info_v161.as_slice(), 161, want())?; |
| 80 | + |
| 81 | + Ok(()) |
| 82 | +} |
0 commit comments