Motr  M0
capa_ut.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012-2020 Seagate Technology LLC and/or its Affiliates
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * For any questions about this software or licensing,
17  * please email opensource@seagate.com or cortx-questions@seagate.com.
18  *
19  */
20 
21 
22 #include "lib/types.h"
23 #include "ut/ut.h"
24 #include "lib/misc.h" /* M0_SET0() */
25 
26 #include "capa/capa.h"
27 
28 /* stub on stub :-) */
30 };
31 
32 static int cog_init(struct capa_object_guard *cog)
33 {
34  return 0;
35 }
36 
37 static void cog_fini(struct capa_object_guard *cog)
38 {
39 }
40 
45 static void capa_test(void)
46 {
47  int ret;
48  struct m0_capa_ctxt ctx;
49  struct m0_object_capa read_capa;
50  struct m0_object_capa write_capa;
51  struct capa_object_guard guard;
52  struct m0_capa_issuer issuer;
53 
54  ret = cog_init(&guard);
55  M0_UT_ASSERT(ret == 0);
56 
57  ret = m0_capa_ctxt_init(&ctx);
58  M0_UT_ASSERT(ret == 0);
59 
60  ret = m0_capa_new(&read_capa,
63  &guard);
64  M0_UT_ASSERT(ret == 0);
65 
66  ret = m0_capa_new(&write_capa,
69  &guard);
70  M0_UT_ASSERT(ret == 0);
71 
72  ret = m0_capa_get(&ctx, &issuer, &read_capa);
73  M0_UT_ASSERT(ret == 0);
74 
75  ret = m0_capa_get(&ctx, &issuer, &write_capa);
76  M0_UT_ASSERT(ret == 0);
77 
78  /* have capability so auth should succeed */
79  ret = m0_capa_auth(&ctx, &write_capa, M0_CAPA_OP_DATA_WRITE);
80  M0_UT_ASSERT(ret == 0);
81 
82  ret = m0_capa_auth(&ctx, &write_capa, M0_CAPA_OP_DATA_READ);
83  M0_UT_ASSERT(ret == 0);
84 
85  m0_capa_put(&ctx, &read_capa);
86  m0_capa_put(&ctx, &write_capa);
87 
88 /* uncomment when realization ready */
89 #if 0
90  /* have NO capability so auth should fail */
91  ret = m0_capa_auth(&ctx, &write_capa, M0_CAPA_OP_DATA_WRITE);
92  M0_UT_ASSERT(ret != 0);
93 
94  ret = m0_capa_auth(&ctx, &write_capa, M0_CAPA_OP_DATA_READ);
95  M0_UT_ASSERT(ret != 0);
96 #endif
97 
98  cog_fini(&guard);
100 }
101 
103  .ts_name = "capa-ut",
104  .ts_init = NULL,
105  .ts_fini = NULL,
106  .ts_tests = {
107  { "capa", capa_test },
108  { NULL, NULL }
109  }
110 };
111 
112 /*
113  * Local variables:
114  * c-indentation-style: "K&R"
115  * c-basic-offset: 8
116  * tab-width: 8
117  * fill-column: 80
118  * scroll-step: 1
119  * End:
120  */
M0_INTERNAL int m0_capa_auth(struct m0_capa_ctxt *ctxt, struct m0_object_capa *capa, enum m0_capa_operation op)
Definition: capa.c:75
static void cog_fini(struct capa_object_guard *cog)
Definition: capa_ut.c:37
#define NULL
Definition: misc.h:38
Definition: ut.h:77
M0_INTERNAL int m0_capa_ctxt_init(struct m0_capa_ctxt *ctxt)
Definition: capa.c:83
M0_INTERNAL void m0_capa_put(struct m0_capa_ctxt *ctxt, struct m0_object_capa *capa)
Definition: capa.c:66
static void capa_test(void)
Definition: capa_ut.c:45
struct m0_ut_suite capa_ut
Definition: capa_ut.c:102
const char * ts_name
Definition: ut.h:99
M0_INTERNAL int m0_capa_new(struct m0_object_capa *capa, enum m0_capa_entity_type type, enum m0_capa_operation opcode, void *data)
Definition: capa.c:41
static int cog_init(struct capa_object_guard *cog)
Definition: capa_ut.c:32
M0_INTERNAL int m0_capa_get(struct m0_capa_ctxt *ctxt, struct m0_capa_issuer *owner, struct m0_object_capa *capa)
Definition: capa.c:54
Definition: nucleus.c:42
M0_INTERNAL void m0_capa_ctxt_fini(struct m0_capa_ctxt *ctxt)
Definition: capa.c:89
#define M0_UT_ASSERT(a)
Definition: ut.h:46