use of com.aliyuncs.fc.client.FunctionComputeClient in project fc-java-sdk by aliyun.
the class FunctionComputeClientTest method testCreateServiceStsTokenNoPassRole.
@Test
public void testCreateServiceStsTokenNoPassRole() throws com.aliyuncs.exceptions.ClientException {
// Use a policy that does not have ram:PassRole, this policy will intersect with the role policy
// Access denied is expected if using STS without PassRole allowed
// Policy intersection doc: https://help.aliyun.com/document_detail/31935.html
String policy = "{\"Version\": \"1\",\"Statement\": [{\"Effect\": \"Allow\",\"Action\": [\"fc:*\"],\"Resource\": [\"*\"]}]}";
Credentials creds = getAssumeRoleCredentials(policy);
client = new FunctionComputeClient(new Config(REGION, ACCOUNT_ID, creds.getAccessKeyId(), creds.getAccessKeySecret(), creds.getSecurityToken(), false));
try {
createService(SERVICE_NAME);
fail("ClientException is expected");
} catch (ClientException e) {
assertTrue(e.getErrorMessage().contains("the caller is not authorized to perform 'ram:PassRole'"));
}
}
use of com.aliyuncs.fc.client.FunctionComputeClient in project fc-java-sdk by aliyun.
the class FunctionComputeClientTest method setup.
@Before
public void setup() {
// Create or clean up everything under the test service
client = new FunctionComputeClient(REGION, ACCOUNT_ID, ACCESS_KEY, SECRET_KEY);
GetServiceRequest getSReq = new GetServiceRequest(SERVICE_NAME);
try {
client.getService(getSReq);
ListFunctionsRequest listFReq = new ListFunctionsRequest(SERVICE_NAME);
ListFunctionsResponse listFResp = client.listFunctions(listFReq);
cleanUpFunctions(SERVICE_NAME, listFResp.getFunctions());
cleanupService(SERVICE_NAME);
} catch (ClientException e) {
if (!ErrorCodes.SERVICE_NOT_FOUND.equals(e.getErrorCode())) {
throw e;
}
}
}
Aggregations