예제 #1
0
        public async Task CreateUserTwiceDeleteUserTwice()
        {
            // Get the access token for the Embedded Social Test Client 1 AAD application
            CertificateHelper certHelper  = new CertificateHelper(ValidSPClient.CertThumbprint, ValidSPClient.ClientId, StoreLocation.CurrentUser);
            string            accessToken = await certHelper.GetAccessToken(ValidSPClient.Authority, ValidSPClient.AppUri);

            string userHandle = HandleGenerator.GenerateShortHandle();
            string auth       = AuthHelper.CreateAADS2SAuth(accessToken, TestConstants.AppKey, userHandle);

            // Set up initial stuff
            SocialPlusClient client = new SocialPlusClient(TestConstants.ServerApiBaseUrl);

            PostUserRequest postUserRequest =
                new PostUserRequest(instanceId: TestConstants.InstanceId, firstName: "Joseph", lastName: "Johnson", bio: "Some Bio");

            HttpOperationResponse <PostUserResponse> postUserOperationResponse1 =
                await client.Users.PostUserWithHttpMessagesAsync(request : postUserRequest, authorization : auth);

            HttpOperationResponse <PostUserResponse> postUserOperationResponse2;

            postUserOperationResponse2 = await client.Users.PostUserWithHttpMessagesAsync(request : postUserRequest, authorization : auth);

            HttpOperationResponse <object> deleteUserOperationResponse1 =
                await client.Users.DeleteUserWithHttpMessagesAsync(authorization : auth);

            HttpOperationResponse <object> deleteUserOperationResponse2 =
                await client.Users.DeleteUserWithHttpMessagesAsync(authorization : auth);

            // Assert correct HTTP error codes
            Assert.IsTrue(postUserOperationResponse1.Response.IsSuccessStatusCode);
            Assert.AreEqual(HttpStatusCode.Conflict, postUserOperationResponse2.Response.StatusCode);
            Assert.IsTrue(deleteUserOperationResponse1.Response.IsSuccessStatusCode);
        }
예제 #2
0
        public async Task CreateDeleteUserWithValidAADTokenValidSPClient()
        {
            // Get the access token for a valid AAD application
            CertificateHelper certHelper  = new CertificateHelper(ValidSPClient.CertThumbprint, ValidSPClient.ClientId, StoreLocation.CurrentUser);
            string            accessToken = await certHelper.GetAccessToken(ValidSPClient.Authority, ValidSPClient.AppUri);

            string userHandle = HandleGenerator.GenerateShortHandle();
            string auth       = AuthHelper.CreateAADS2SAuth(accessToken, TestConstants.AppKey, userHandle);

            // Set up initial stuff
            SocialPlusClient client = new SocialPlusClient(TestConstants.ServerApiBaseUrl);

            PostUserRequest postUserRequest =
                new PostUserRequest(instanceId: TestConstants.InstanceId, firstName: "Joseph", lastName: "Johnson", bio: "Some Bio");
            HttpOperationResponse <PostUserResponse> postUserOperationResponse =
                await client.Users.PostUserWithHttpMessagesAsync(request : postUserRequest, authorization : auth);

            HttpOperationResponse <object> deleteUserOperationResponse =
                await client.Users.DeleteUserWithHttpMessagesAsync(authorization : auth);

            // Assert correct HTTP error codes
            Assert.IsTrue(postUserOperationResponse.Response.IsSuccessStatusCode);
            Assert.IsTrue(deleteUserOperationResponse.Response.IsSuccessStatusCode);

            // PostUser also returns a non-empty session token and the user handle
            Assert.IsFalse(string.IsNullOrEmpty(postUserOperationResponse.Body.SessionToken));
            Assert.AreEqual(userHandle, postUserOperationResponse.Body.UserHandle);
        }
예제 #3
0
        public async Task CreateDeleteUserWithValidAADTokenInvalidAudience()
        {
            // Get the access token for SocialPlus AAD application. While this is a valid AAD token,
            // the service checks that the token's audience is "https://embeddedsocial.microsoft.com/testclient1".
            // In this case, it is not. Instead, the audience is "https://embeddedsocial.microsoft.com/testclient2"
            CertificateHelper certHelper  = new CertificateHelper(InvalidSPClient.CertThumbprint, InvalidSPClient.ClientId, StoreLocation.CurrentUser);
            string            accessToken = await certHelper.GetAccessToken(InvalidSPClient.Authority, InvalidSPClient.AppUri);

            string userHandle = HandleGenerator.GenerateShortHandle();
            string auth       = AuthHelper.CreateAADS2SAuth(accessToken, TestConstants.AppKey, userHandle);

            // Set up initial stuff
            SocialPlusClient client = new SocialPlusClient(TestConstants.ServerApiBaseUrl);

            PostUserRequest postUserRequest =
                new PostUserRequest(instanceId: TestConstants.InstanceId, firstName: "Joseph", lastName: "Johnson", bio: "Some Bio");
            HttpOperationResponse <PostUserResponse> postUserOperationResponse =
                await client.Users.PostUserWithHttpMessagesAsync(request : postUserRequest, authorization : accessToken);

            // the above post user operation should fail.  but in case it doesn't, we clean up the user we created
            HttpOperationResponse <object> deleteUserOperationResponse =
                await client.Users.DeleteUserWithHttpMessagesAsync(authorization : accessToken);

            // both the create and delete operations should fail
            Assert.AreEqual(HttpStatusCode.Unauthorized, postUserOperationResponse.Response.StatusCode);
            Assert.AreEqual(HttpStatusCode.Unauthorized, deleteUserOperationResponse.Response.StatusCode);
        }
예제 #4
0
        public async Task CreateDeleteUserWithInvalidAADToken()
        {
            // Create fake access token
            string fakeAccessToken = "Stefan Rules!";
            string userHandle      = HandleGenerator.GenerateShortHandle();
            string auth            = AuthHelper.CreateAADS2SAuth(fakeAccessToken, TestConstants.AppKey, userHandle);

            // Set up initial stuff
            SocialPlusClient client = new SocialPlusClient(TestConstants.ServerApiBaseUrl);

            PostUserRequest postUserRequest =
                new PostUserRequest(instanceId: TestConstants.InstanceId, firstName: "Joseph", lastName: "Johnson", bio: "Some Bio");
            HttpOperationResponse <PostUserResponse> postUserOperationResponse =
                await client.Users.PostUserWithHttpMessagesAsync(request : postUserRequest, authorization : auth);

            // the above post user operation should fail.  but in case it doesn't, we clean up the user we created
            HttpOperationResponse <object> deleteUserOperationResponse =
                await client.Users.DeleteUserWithHttpMessagesAsync(authorization : auth);

            // both the create and delete operations should fail
            Assert.AreEqual(HttpStatusCode.Unauthorized, postUserOperationResponse.Response.StatusCode);
            Assert.AreEqual(HttpStatusCode.Unauthorized, deleteUserOperationResponse.Response.StatusCode);
        }