Skip to content
This repository has been archived by the owner on Mar 9, 2023. It is now read-only.

Cpp app shared #8

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -707,35 +707,53 @@ public boolean isConfigurationSharedWithAccount(Account account, Configuration c
}
}

public boolean checkForOverlapingAmongTeams(Set<String> configSharedWithTeams, Set<String> appSharedWithTeams, Set<String> accountMemberOfTeams) {
//Retain teams of Configuration Parameters intersect with Application
logger.info("Checking if shared cloudProviderParameters overlapping teams");
configSharedWithTeams.retainAll(appSharedWithTeams);
if(!configSharedWithTeams.isEmpty()){
configSharedWithTeams.retainAll(accountMemberOfTeams);
if(!configSharedWithTeams.isEmpty())
return true;
}
return false;
}

public boolean canConfigurationBeUsedForApplication(Configuration configuration, Application application, Account account) {
//Check configuration is owned by user
logger.info("Checking if configuration '" + configuration.getName() +
"' can be used for application '" + application.getName() + "'" +
"by user '" + account.getGivenName() + "'"
);
try{

CloudProviderParameters cloudProviderParameters = cppService.findByReference(configuration.getCloudProviderParametersReference());
if (configuration.getAccount().equals(account)) {
//Checking credentials is can be used on any application
logger.debug("The user is the configuration owner, so check if cloud credential is usable ");
return cppService.canCredentialBeUsedForApplication(cloudProviderParameters, application, account);
} else {
//Check configuration is shared with user
if (isConfigurationSharedWithAccount(account, configuration)) {
//Getting corresponding teams
Set<String> configSharedWithTeams = configuration.getSharedTeamNames();
Set<String> accountMemberOfTeams = account.getMembershipTeamNames();
Set<String> appSharedWithTeams = application.getSharedTeamNames();
return cppService.checkForOverlapingAmongTeams(configSharedWithTeams,appSharedWithTeams, accountMemberOfTeams);
boolean canConfigurationBeUsedForApplication = this.checkForOverlapingAmongTeams(configuration.getSharedTeamNames(), application.getSharedTeamNames(), account.getMembershipTeamNames());

if(canConfigurationBeUsedForApplication){
/**
* If the configuration is shared in the same team as application,
* the user can deploy
*/
return true;
}else{
/**
* if the cloud credential is owned or shared in the same team as application,
* the user can deploy the application, provided he owns the configuration
*/
if(cppService.canCredentialBeUsedForApplication(cloudProviderParameters, application, account)){

if(configuration.getAccount().getReference().equals(account.getReference())){
//configuration is owned
return true;
}
}
}
return false;

}catch(CloudProviderParametersNotFoundException e){
logger.error("The associated cloud provider parameter is not found, it is obsolete");
return false;
}

return false;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -483,5 +483,62 @@ public void testCreateConfigurationResource(){

}

@Test
public void testCanConfigurationBeUsedForApplicationCCPAAPSharedInSameTeamButNotConfiguration(){

Set<Team> cppSharedTeams = new HashSet<>();
cppSharedTeams.add(team1);
cpp1.setSharedWithTeams(cppSharedTeams);
team1.getCppBelongingToTeam().add(cpp1);

Set<Team> appSharedTeams = new HashSet<>();
appSharedTeams.add(team1);
application.setSharedWithTeams(appSharedTeams);
team1.getApplicationsBelongingToTeam().add(application);


Set<Team> configurationSharedWithTeams = new HashSet<>();
configurationSharedWithTeams.add(team2);
configuration1.setSharedWithTeams(configurationSharedWithTeams);
team2.getConfigurationsBelongingToTeam().add(configuration1);

given(cppService.isCloudProviderParametersSharedWithAccount(memberAccount,cpp1)).willCallRealMethod();
given(cppService.findByReference(cppReference1)).willReturn(cpp1);
given(cppService.canCredentialBeUsedForApplication(cpp1, application, memberAccount)).willCallRealMethod();
given(cppService.checkForOverlapingAmongTeams(Mockito.anySet(),Mockito.anySet(), Mockito.anySet())).willCallRealMethod();
boolean canConfigurationBeUsedForApplication = testCandidate.canConfigurationBeUsedForApplication(configuration1, application, memberAccount);
assertTrue(canConfigurationBeUsedForApplication == false);

}

@Test
public void testCanConfigurationBeUsedForApplicationCCPAAPConfigurationSharedInSameTeam(){

Set<Team> cppSharedTeams = new HashSet<>();
cppSharedTeams.add(team1);
cpp1.setSharedWithTeams(cppSharedTeams);
team1.getCppBelongingToTeam().add(cpp1);

Set<Team> appSharedTeams = new HashSet<>();
appSharedTeams.add(team1);
application.setSharedWithTeams(appSharedTeams);
team1.getApplicationsBelongingToTeam().add(application);


Set<Team> configurationSharedWithTeams = new HashSet<>();
configurationSharedWithTeams.add(team1);
configuration1.setSharedWithTeams(configurationSharedWithTeams);
team1.getConfigurationsBelongingToTeam().add(configuration1);

given(cppService.isCloudProviderParametersSharedWithAccount(memberAccount,cpp1)).willCallRealMethod();
given(cppService.findByReference(cppReference1)).willReturn(cpp1);
given(cppService.canCredentialBeUsedForApplication(cpp1, application, memberAccount)).willCallRealMethod();
given(cppService.checkForOverlapingAmongTeams(Mockito.anySet(),Mockito.anySet(), Mockito.anySet())).willCallRealMethod();
boolean canConfigurationBeUsedForApplication = testCandidate.canConfigurationBeUsedForApplication(configuration1, application, memberAccount);
assertTrue(canConfigurationBeUsedForApplication == true);

}

}