<commit_before>/*
 * Copyright 2014 Netflix, 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.netflix.spinnaker.front50.filters

import spock.lang.Specification

import javax.servlet.FilterChain
import javax.servlet.RequestDispatcher
import javax.servlet.http.HttpServletRequest
import javax.servlet.http.HttpServletResponse

class AccountHostnameFilterSpec extends Specification {

  void "if hostname matches vip pattern, internal forward appropriately"() {
    setup:
    def req = Mock(HttpServletRequest)
    def res = Mock(HttpServletResponse)
    def chain = Mock(FilterChain)
    def filter = new AccountHostnameFilter(front50Domain: "netflix.net", front50Prefix: "front50")

    when:
    filter.doFilter(req, res, chain)

    then:
    1 * req.getRequestURL() >> new StringBuffer("http://front50.test.netflix.net")
    1 * req.getRequestURI() >> "/applications"
    1 * req.getRequestDispatcher("/test/applications") >> Mock(RequestDispatcher)
  }

  void "hostanme matches that already have the account pattner don't forward"() {
    setup:
    def req = Mock(HttpServletRequest)
    def res = Mock(HttpServletResponse)
    def chain = Mock(FilterChain)
    def filter = new AccountHostnameFilter(front50Domain: "netflix.net", front50Prefix: "front50")

    when:
    filter.doFilter(req, res, chain)

    then:
    1 * req.getRequestURL() >> new StringBuffer("http://front50.test.netflix.net")
    1 * req.getRequestURI() >> "/test/applications"
    0 * req.getRequestDispatcher("/test/applications") >> Mock(RequestDispatcher)
  }
}
<commit_msg>minor update to spec test case<commit_after>/*
 * Copyright 2014 Netflix, 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.netflix.spinnaker.front50.filters

import spock.lang.Specification

import javax.servlet.FilterChain
import javax.servlet.RequestDispatcher
import javax.servlet.http.HttpServletRequest
import javax.servlet.http.HttpServletResponse

class AccountHostnameFilterSpec extends Specification {

  void "if hostname matches vip pattern, internal forward appropriately"() {
    setup:
    def req = Mock(HttpServletRequest)
    def res = Mock(HttpServletResponse)
    def chain = Mock(FilterChain)
    def filter = new AccountHostnameFilter(front50Domain: "netflix.net", front50Prefix: "front50")

    when:
    filter.doFilter(req, res, chain)

    then:
    1 * req.getRequestURL() >> new StringBuffer("http://front50.test.netflix.net")
    1 * req.getRequestURI() >> "/applications"
    1 * req.getRequestDispatcher("/test/applications") >> Mock(RequestDispatcher)
  }

  void "hostname matches that already have the account partner don't forward"() {
    setup:
    def req = Mock(HttpServletRequest)
    def res = Mock(HttpServletResponse)
    def chain = Mock(FilterChain)
    def filter = new AccountHostnameFilter(front50Domain: "netflix.net", front50Prefix: "front50")

    when:
    filter.doFilter(req, res, chain)

    then:
    1 * req.getRequestURL() >> new StringBuffer("http://front50.test.netflix.net")
    1 * req.getRequestURI() >> "/test/applications"
    0 * req.getRequestDispatcher("/test/applications") >> Mock(RequestDispatcher)
  }
}

{'fraction_non_alphanumeric': 0.09968995945623658, 'fraction_numerical': 0.015263534462198903, 'mean_word_length': 4.152334152334152, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 27, 'https://': 0, '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': '1225083', 'n_tokens_mistral': 1197, 'n_tokens_neox': 1154, 'n_words': 371}