<commit_before>/*
 * Copyright 2016 Stormpath, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.stormpath.tck.forgot

import com.jayway.restassured.http.ContentType
import com.jayway.restassured.response.Cookie
import com.jayway.restassured.response.Cookies
import com.stormpath.tck.AbstractIT
import com.stormpath.tck.util.*
import com.stormpath.tck.responseSpecs.*
import org.testng.annotations.BeforeClass
import org.testng.annotations.Test

import static com.jayway.restassured.RestAssured.*
import static org.testng.Assert.*
import static org.hamcrest.Matchers.*
import static com.stormpath.tck.util.FrameworkConstants.ForgotRoute

@Test
class ForgotPasswordIT extends AbstractIT {
    private TestAccount account = new TestAccount()

    @BeforeClass
    private void createTestAccount() throws Exception {
        account.registerOnServer()
        deleteOnClassTeardown(account.href)
    }

    /** Only GET and POST should be handled
     * @see <a href="https://github.com/stormpath/stormpath-framework-tck/issues/165">#165</a>
     * @throws Exception
     */
    @Test
    public void doNotHandlePut() throws Exception {
        put(ForgotRoute)
            .then()
                .assertThat().statusCode(404)
    }

    /** Only GET and POST should be handled
     * @see <a href="https://github.com/stormpath/stormpath-framework-tck/issues/165">#165</a>
     * @throws Exception
     */
    @Test
    public void doNotHandleDelete() throws Exception {
        delete(ForgotRoute)
            .then()
                .assertThat().statusCode(404)
    }

    /** GET should not be handled for JSON requests
     * @see <a href="https://github.com/stormpath/stormpath-framework-tck/issues/215">#215</a>
     * @throws Exception
     */
    @Test
    public void doNotHandleJsonGet() throws Exception {
        given()
            .accept(ContentType.JSON)
        .when()
            .get(ForgotRoute)
        .then()
            .statusCode(404)
    }
}<commit_msg>JSON POST should respond with 200 (fixes #142)<commit_after>/*
 * Copyright 2016 Stormpath, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.stormpath.tck.forgot

import com.jayway.restassured.http.ContentType
import com.jayway.restassured.response.Cookie
import com.jayway.restassured.response.Cookies
import com.stormpath.tck.AbstractIT
import com.stormpath.tck.util.*
import com.stormpath.tck.responseSpecs.*
import org.testng.annotations.BeforeClass
import org.testng.annotations.Test

import static com.jayway.restassured.RestAssured.*
import static org.testng.Assert.*
import static org.hamcrest.Matchers.*
import static com.stormpath.tck.util.FrameworkConstants.ForgotRoute

@Test
class ForgotPasswordIT extends AbstractIT {
    private TestAccount account = new TestAccount()

    @BeforeClass
    private void createTestAccount() throws Exception {
        account.registerOnServer()
        deleteOnClassTeardown(account.href)
    }

    /** Only GET and POST should be handled
     * @see <a href="https://github.com/stormpath/stormpath-framework-tck/issues/165">#165</a>
     * @throws Exception
     */
    @Test
    public void doNotHandlePut() throws Exception {
        put(ForgotRoute)
            .then()
                .assertThat().statusCode(404)
    }

    /** Only GET and POST should be handled
     * @see <a href="https://github.com/stormpath/stormpath-framework-tck/issues/165">#165</a>
     * @throws Exception
     */
    @Test
    public void doNotHandleDelete() throws Exception {
        delete(ForgotRoute)
            .then()
                .assertThat().statusCode(404)
    }

    /** GET should not be handled for JSON requests
     * @see <a href="https://github.com/stormpath/stormpath-framework-tck/issues/215">#215</a>
     * @throws Exception
     */
    @Test
    public void doNotHandleJsonGet() throws Exception {
        given()
            .accept(ContentType.JSON)
        .when()
            .get(ForgotRoute)
        .then()
            .statusCode(404)
    }

    /** POST requests preferring application/json should respond with 200 OK
     * @see <a href="https://github.com/stormpath/stormpath-framework-tck/issues/142">#142</a>
     * @throws Exception
     */
    @Test
    public void returnsSuccessForValidEmail() throws Exception {
        given()
            .accept(ContentType.JSON)
            .contentType(ContentType.JSON)
            .body([ "email": account.email ])
        .when()
            .post(ForgotRoute)
        .then()
            .statusCode(200)
    }

    /** POST requests preferring application/json should respond with 200 OK
     * @see <a href="https://github.com/stormpath/stormpath-framework-tck/issues/142">#142</a>
     * @throws Exception
     */
    @Test
    public void returnsSuccessForInvalidEmail() throws Exception {
        given()
            .accept(ContentType.JSON)
            .contentType(ContentType.JSON)
            .body([ "email": "<EMAIL>" ])
        .when()
            .post(ForgotRoute)
        .then()
            .statusCode(200)
    }
}
{'fraction_non_alphanumeric': 0.10566037735849057, 'fraction_numerical': 0.016406890894175553, 'mean_word_length': 2.769944341372913, 'pattern_counts': {'":': 2, '<': 20, '<?xml version=': 0, '>': 20, 'https://': 8, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3834601', 'n_tokens_mistral': 1817, 'n_tokens_neox': 1704, 'n_words': 463}