1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-28 19:35:36 +02:00

fixed backdoor access to list of providers inside configuration

This commit is contained in:
Andrew Gvozdev 2011-09-23 17:37:48 -04:00
parent 57afab135d
commit c410b4b521
2 changed files with 35 additions and 9 deletions

View file

@ -184,6 +184,32 @@ public class LanguageSettingsPersistenceProjectTests extends TestCase {
// test passes if no exception was thrown // test passes if no exception was thrown
} }
/**
*/
public void testProjectDescription_PreventBackDoorAccess() throws Exception {
// create a project
IProject project = ResourceHelper.createCDTProjectWithConfig(getName());
// get project descriptions
ICProjectDescription writableProjDescription = coreModel.getProjectDescription(project);
assertNotNull(writableProjDescription);
ICConfigurationDescription[] cfgDescriptions = writableProjDescription.getConfigurations();
assertEquals(1, cfgDescriptions.length);
ICConfigurationDescription cfgDescription = cfgDescriptions[0];
List<ILanguageSettingsProvider> originalProviders = cfgDescription.getLanguageSettingProviders();
int originalSize = originalProviders.size();
// create new provider list
LanguageSettingsSerializable mockProvider = new MockEditableProvider(PROVIDER_0, PROVIDER_NAME_0);
List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>(originalProviders);
providers.add(mockProvider);
assertTrue(originalSize != providers.size());
// changing providers shouldn't affect the original list
cfgDescription.setLanguageSettingProviders(providers);
assertEquals(originalSize, originalProviders.size());
}
/** /**
*/ */
public void testProjectDescription_ReadWriteProviders() throws Exception { public void testProjectDescription_ReadWriteProviders() throws Exception {
@ -196,7 +222,7 @@ public class LanguageSettingsPersistenceProjectTests extends TestCase {
assertNotNull(prjDescription); assertNotNull(prjDescription);
ICConfigurationDescription cfgDescription = prjDescription.getDefaultSettingConfiguration(); ICConfigurationDescription cfgDescription = prjDescription.getDefaultSettingConfiguration();
assertNotNull(cfgDescription); assertNotNull(cfgDescription);
// try to write to it // try to write to it
try { try {
List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>(); List<ILanguageSettingsProvider> providers = new ArrayList<ILanguageSettingsProvider>();
@ -206,10 +232,10 @@ public class LanguageSettingsPersistenceProjectTests extends TestCase {
// exception is expected // exception is expected
} }
} }
List<ICLanguageSettingEntry> entries = new ArrayList<ICLanguageSettingEntry>(); List<ICLanguageSettingEntry> entries = new ArrayList<ICLanguageSettingEntry>();
entries.add(new CIncludePathEntry("path0", 0)); entries.add(new CIncludePathEntry("path0", 0));
{ {
// get project descriptions // get project descriptions
ICProjectDescription writableProjDescription = coreModel.getProjectDescription(project); ICProjectDescription writableProjDescription = coreModel.getProjectDescription(project);
@ -217,7 +243,7 @@ public class LanguageSettingsPersistenceProjectTests extends TestCase {
ICConfigurationDescription[] cfgDescriptions = writableProjDescription.getConfigurations(); ICConfigurationDescription[] cfgDescriptions = writableProjDescription.getConfigurations();
assertEquals(1, cfgDescriptions.length); assertEquals(1, cfgDescriptions.length);
ICConfigurationDescription cfgDescription = cfgDescriptions[0]; ICConfigurationDescription cfgDescription = cfgDescriptions[0];
// create a provider // create a provider
LanguageSettingsSerializable mockProvider = new MockEditableProvider(PROVIDER_0, PROVIDER_NAME_0); LanguageSettingsSerializable mockProvider = new MockEditableProvider(PROVIDER_0, PROVIDER_NAME_0);
mockProvider.setStoringEntriesInProjectArea(true); mockProvider.setStoringEntriesInProjectArea(true);
@ -227,7 +253,7 @@ public class LanguageSettingsPersistenceProjectTests extends TestCase {
cfgDescription.setLanguageSettingProviders(providers); cfgDescription.setLanguageSettingProviders(providers);
List<ILanguageSettingsProvider> storedProviders = cfgDescription.getLanguageSettingProviders(); List<ILanguageSettingsProvider> storedProviders = cfgDescription.getLanguageSettingProviders();
assertEquals(1, storedProviders.size()); assertEquals(1, storedProviders.size());
// apply new project description to the project model // apply new project description to the project model
coreModel.setProjectDescription(project, writableProjDescription); coreModel.setProjectDescription(project, writableProjDescription);
} }
@ -238,14 +264,14 @@ public class LanguageSettingsPersistenceProjectTests extends TestCase {
ICConfigurationDescription[] cfgDescriptions = readOnlyProjDescription.getConfigurations(); ICConfigurationDescription[] cfgDescriptions = readOnlyProjDescription.getConfigurations();
assertEquals(1, cfgDescriptions.length); assertEquals(1, cfgDescriptions.length);
ICConfigurationDescription cfgDescription = cfgDescriptions[0]; ICConfigurationDescription cfgDescription = cfgDescriptions[0];
List<ILanguageSettingsProvider> providers = cfgDescription.getLanguageSettingProviders(); List<ILanguageSettingsProvider> providers = cfgDescription.getLanguageSettingProviders();
assertEquals(1, providers.size()); assertEquals(1, providers.size());
ILanguageSettingsProvider loadedProvider = providers.get(0); ILanguageSettingsProvider loadedProvider = providers.get(0);
assertTrue(loadedProvider instanceof LanguageSettingsSerializable); assertTrue(loadedProvider instanceof LanguageSettingsSerializable);
assertEquals(PROVIDER_0, loadedProvider.getId()); assertEquals(PROVIDER_0, loadedProvider.getId());
assertEquals(PROVIDER_NAME_0, loadedProvider.getName()); assertEquals(PROVIDER_NAME_0, loadedProvider.getName());
List<ICLanguageSettingEntry> actual = loadedProvider.getSettingEntries(cfgDescription, null, null); List<ICLanguageSettingEntry> actual = loadedProvider.getSettingEntries(cfgDescription, null, null);
assertEquals(entries.get(0), actual.get(0)); assertEquals(entries.get(0), actual.get(0));
assertEquals(entries.size(), actual.size()); assertEquals(entries.size(), actual.size());
@ -270,7 +296,7 @@ public class LanguageSettingsPersistenceProjectTests extends TestCase {
assertEquals(entries.size(), actual.size()); assertEquals(entries.size(), actual.size());
} }
} }
/** /**
*/ */
public void testWorkspacePersistence_ModifiedExtensionProvider() throws Exception { public void testWorkspacePersistence_ModifiedExtensionProvider() throws Exception {

View file

@ -989,7 +989,7 @@ public class CConfigurationSpecSettings implements ICSettingsStorage{
* @param providers - list of providers to keep in the specs. * @param providers - list of providers to keep in the specs.
*/ */
public void setLanguageSettingProviders(List<ILanguageSettingsProvider> providers) { public void setLanguageSettingProviders(List<ILanguageSettingsProvider> providers) {
fLanguageSettingsProviders.clear(); fLanguageSettingsProviders = new ArrayList<ILanguageSettingsProvider>(0);
Set<String> ids = new HashSet<String>(); Set<String> ids = new HashSet<String>();
for (ILanguageSettingsProvider provider : providers) { for (ILanguageSettingsProvider provider : providers) {
String id = provider.getId(); String id = provider.getId();