public ApplicationController(IMapper mapper
                              , IDeleteApplicationCommand deleteApplicationCommand
                              , IAddApplicationCommand addApplicationCommand
                              , IEditApplicationCommand editApplicationCommand
                              , GetApplicationByIdQuery getApplicationByIdQuery
                              , IGetVendorByIdQuery getVendorByIdQuery
                              , GetClaimSetNamesQuery getClaimSetNamesQuery
                              , GetProfilesQuery getProfilesQuery
                              , RegenerateApiClientSecretCommand regenerateApiClientSecretCommand
                              , IOdsApiFacadeFactory odsApiFacadeFactory
                              , InstanceContext instanceContext
                              , ITabDisplayService tabDisplayService
                              , IOdsApiConnectionInformationProvider apiConnectionInformationProvider
                              , IGetVendorsQuery getVendorsQuery)
 {
     _mapper = mapper;
     _deleteApplicationCommand         = deleteApplicationCommand;
     _addApplicationCommand            = addApplicationCommand;
     _editApplicationCommand           = editApplicationCommand;
     _getApplicationByIdQuery          = getApplicationByIdQuery;
     _getVendorByIdQuery               = getVendorByIdQuery;
     _getClaimSetNamesQuery            = getClaimSetNamesQuery;
     _getProfilesQuery                 = getProfilesQuery;
     _regenerateApiClientSecretCommand = regenerateApiClientSecretCommand;
     _odsApiFacadeFactory              = odsApiFacadeFactory;
     _instanceContext   = instanceContext;
     _tabDisplayService = tabDisplayService;
     _apiConnectionInformationProvider = apiConnectionInformationProvider;
     _getVendorsQuery = getVendorsQuery;
 }
        public void ShouldUpdateApiClientSecret()
        {
            var vendor = new Vendor
            {
                VendorNamespacePrefixes = new List <VendorNamespacePrefix> {
                    new VendorNamespacePrefix {
                        NamespacePrefix = "http://tests.com"
                    }
                },
                VendorName = "Integration Tests"
            };

            var user = new VendorUser
            {
                Email    = "*****@*****.**",
                FullName = "Integration Tests",
                Vendor   = vendor
            };

            var profile = new Profile
            {
                ProfileName = "Test Profile"
            };

            var apiClient = new ApiClient(true)
            {
                Name = "Integration Test"
            };

            var application = new Application
            {
                ApplicationName       = "Test Application",
                ClaimSetName          = "FakeClaimSet",
                ApiClients            = new List <ApiClient>(),
                Vendor                = vendor,
                Profiles              = new List <Profile>(),
                OperationalContextUri = OperationalContext.DefaultOperationalContextUri
            };

            application.ApiClients.Add(apiClient);
            application.Profiles.Add(profile);

            Save(vendor, user, profile, application);

            var orignalKey     = apiClient.Key;
            var originalSecret = apiClient.Secret;

            var command = new RegenerateApiClientSecretCommand(SetupContext);
            var result  = command.Execute(application.ApplicationId);

            var updatedApiClient = TestContext.Clients.Single(c => c.ApiClientId == apiClient.ApiClientId);

            result.Key.ShouldBe(orignalKey);
            result.Secret.ShouldNotBe(originalSecret);
            result.Secret.ShouldNotBeEmpty();

            updatedApiClient.Key.ShouldBe(result.Key);
            updatedApiClient.Secret.ShouldBe(result.Secret);
        }
Beispiel #3
0
    public async Task <IResult> HandleResetCredentials(RegenerateApiClientSecretCommand resetSecretCommand, IMapper mapper, int id)
    {
        var resetApplicationSecret = await Task.Run(() => resetSecretCommand.Execute(id));

        var model = mapper.Map <ApplicationResult>(resetApplicationSecret);

        return(AdminApiResponse <ApplicationResult> .Updated(model, "Application secret"));
    }
 public void ShouldFailIfApplicationDoesNotExist()
 {
     Scoped <IUsersContext>(usersContext =>
     {
         var command = new RegenerateApiClientSecretCommand(usersContext);
         Assert.Throws <InvalidOperationException>(() => command.Execute(0));
     });
 }
        public void ShouldReportFailureIfApiClientDoesNotExist()
        {
            var application = new Application
            {
                ApplicationName       = "Api Client Secret Test App",
                OperationalContextUri = OperationalContext.DefaultOperationalContextUri
            };

            Save(application);

            var command = new RegenerateApiClientSecretCommand(TestContext);

            Assert.Throws <InvalidOperationException>(() => command.Execute(application.ApplicationId));
        }
 public ApplicationController(IMapper mapper
                              , IDeleteApplicationCommand deleteApplicationCommand
                              , IAddApplicationCommand addApplicationCommand
                              , IEditApplicationCommand editApplicationCommand
                              , GetApplicationByIdQuery getApplicationByIdQuery
                              , IGetVendorByIdQuery getVendorByIdQuery
                              , GetClaimSetNamesQuery getClaimSetNamesQuery
                              , GetProfilesQuery getProfilesQuery
                              , RegenerateApiClientSecretCommand regenerateApiClientSecretCommand
                              , IOdsApiFacadeFactory odsApiFacadeFactory
                              , InstanceContext instanceContext)
 {
     _mapper = mapper;
     _deleteApplicationCommand         = deleteApplicationCommand;
     _addApplicationCommand            = addApplicationCommand;
     _editApplicationCommand           = editApplicationCommand;
     _getApplicationByIdQuery          = getApplicationByIdQuery;
     _getVendorByIdQuery               = getVendorByIdQuery;
     _getClaimSetNamesQuery            = getClaimSetNamesQuery;
     _getProfilesQuery                 = getProfilesQuery;
     _regenerateApiClientSecretCommand = regenerateApiClientSecretCommand;
     _odsApiFacadeFactory              = odsApiFacadeFactory;
     _instanceContext = instanceContext;
 }
        public void ShouldUpdateApiClientSecret()
        {
            var vendor = new Vendor
            {
                VendorNamespacePrefixes = new List <VendorNamespacePrefix> {
                    new VendorNamespacePrefix {
                        NamespacePrefix = "http://tests.com"
                    }
                },
                VendorName = "Integration Tests"
            };

            var user = new VendorUser
            {
                Email    = "*****@*****.**",
                FullName = "Integration Tests",
                Vendor   = vendor
            };

            var profile = new Profile
            {
                ProfileName = "Test Profile"
            };

            var apiClient = new ApiClient(true)
            {
                Name = "Integration Test"
            };

            var application = new Application
            {
                ApplicationName       = "Test Application",
                ClaimSetName          = "FakeClaimSet",
                ApiClients            = new List <ApiClient>(),
                Vendor                = vendor,
                Profiles              = new List <Profile>(),
                OperationalContextUri = OperationalContext.DefaultOperationalContextUri
            };

            application.ApiClients.Add(apiClient);
            application.Profiles.Add(profile);

            Save(vendor, user, profile, application);

            var orignalKey     = apiClient.Key;
            var originalSecret = apiClient.Secret;

            //Simulate the automatic hashing performed by using the key/secret on the API.
            Transaction(usersContext =>
            {
                var odsSideApiClient            = usersContext.Clients.Single(c => c.ApiClientId == apiClient.ApiClientId);
                odsSideApiClient.Secret         = "SIMULATED HASH OF " + originalSecret;
                odsSideApiClient.SecretIsHashed = true;
            });

            RegenerateApiClientSecretResult result = null;

            Scoped <IUsersContext>(usersContext =>
            {
                var command = new RegenerateApiClientSecretCommand(usersContext);
                result      = command.Execute(application.ApplicationId);
            });

            var updatedApiClient = Transaction(usersContext => usersContext.Clients.Single(c => c.ApiClientId == apiClient.ApiClientId));

            result.Key.ShouldBe(orignalKey);
            result.Secret.ShouldNotBe(originalSecret);
            result.Secret.ShouldNotBe("SIMULATED HASH OF " + originalSecret);
            result.Secret.ShouldNotBeEmpty();

            updatedApiClient.Key.ShouldBe(result.Key);
            updatedApiClient.Secret.ShouldBe(result.Secret);
            updatedApiClient.SecretIsHashed.ShouldBe(false);
        }