2 * Copyright (c) 2000-2001,2004 Apple Computer, Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
28 // testacls - ACL-related test cases.
30 #include "testclient.h"
31 #include "testutils.h"
32 #include <Security/osxsigner.h>
34 using namespace CodeSigning
;
38 // Authorization test.
39 // This tests the authorization API support.
40 // @@@ Incomplete and not satisfactory.
44 printf("* authorization test\n");
45 ClientSession
ss(CssmAllocator::standard(), CssmAllocator::standard());
47 // make a simple authorization query
48 AuthorizationBlob auth
;
49 AuthorizationItem testingItem
= { "debug.testing", 0, NULL
, NULL
};
50 AuthorizationItem testingMoreItem
= { "debug.testing.more", 0, NULL
, NULL
};
51 AuthorizationItem denyItem
= { "debug.deny", 0, NULL
, NULL
};
52 AuthorizationItemSet request
= { 1, &testingItem
};
53 ss
.authCreate(&request
, NULL
/*environment*/,
54 kAuthorizationFlagInteractionAllowed
|
55 kAuthorizationFlagExtendRights
|
56 kAuthorizationFlagPartialRights
,
58 detail("Initial authorization obtained");
60 // ask for rights from this authorization
62 AuthorizationItem moreItems
[3] = { testingItem
, denyItem
, testingMoreItem
};
63 AuthorizationItemSet moreRequests
= { 3, moreItems
};
64 AuthorizationItemSet
*rightsVector
;
65 ss
.authCopyRights(auth
, &moreRequests
, NULL
/*environment*/,
66 kAuthorizationFlagInteractionAllowed
|
67 kAuthorizationFlagExtendRights
|
68 kAuthorizationFlagPartialRights
,
70 if (rightsVector
->count
!= 2)
71 error("COPYRIGHTS RETURNED %d RIGHTS (EXPECTED 2)", int(rightsVector
->count
));
72 // the output rights could be in either order -- be flexible
74 rights
.insert(rightsVector
->items
[0].name
);
75 rights
.insert(rightsVector
->items
[1].name
);
76 assert(rights
.find("debug.testing") != rights
.end() &&
77 rights
.find("debug.testing.more") != rights
.end());
79 detail("CopyRights okay");
82 // ask for the impossible
84 AuthorizationBlob badAuth
;
85 AuthorizationItem badItem
= { "debug.deny", 0, NULL
, NULL
};
86 AuthorizationItemSet badRequest
= { 1, &badItem
};
87 ss
.authCreate(&badRequest
, NULL
/*environment*/,
88 kAuthorizationFlagInteractionAllowed
|
89 kAuthorizationFlagExtendRights
,
91 error("AUTHORIZED debug.deny OPERATION");
92 } catch (CssmCommonError
&err
) {
93 detail(err
, "debug.deny authorization denied properly");
97 AuthorizationExternalForm extForm
;
98 ss
.authExternalize(auth
, extForm
);
101 AuthorizationBlob auth2
;
102 ss
.authInternalize(extForm
, auth2
);
104 // make sure it still works
106 AuthorizationItem moreItems
[2] = { testingItem
, denyItem
};
107 AuthorizationItemSet moreRequests
= { 2, moreItems
};
108 AuthorizationItemSet
*rightsVector
;
109 ss
.authCopyRights(auth2
, &moreRequests
, NULL
/*environment*/,
110 kAuthorizationFlagInteractionAllowed
|
111 kAuthorizationFlagExtendRights
|
112 kAuthorizationFlagPartialRights
,
114 if (rightsVector
->count
!= 1)
115 error("COPYRIGHTS RETURNED %d RIGHTS (EXPECTED 1)", int(rightsVector
->count
));
116 assert(!strcmp(rightsVector
->items
[0].name
, "debug.testing"));
118 detail("Re-internalized authorization checks out okay");
120 // try it with no rights output (it's optional)
121 ss
.authCopyRights(auth2
, &moreRequests
, NULL
/*environment*/,
122 kAuthorizationFlagPartialRights
, NULL
);
123 detail("authCopyRights partial success OK (with no output)");
125 // but this will fail if we want ALL rights...
127 ss
.authCopyRights(auth2
, &moreRequests
, NULL
/*environment*/,
128 kAuthorizationFlagDefaults
, NULL
);
129 error("authCopyRights succeeded with (only) partial success");
130 } catch (CssmError
&err
) {
131 detail("authCopyRight failed for (only) partial success");