<commit_before>package se.su.it.signuptool

import org.springframework.web.context.request.RequestAttributes
import org.springframework.web.context.request.RequestContextHolder
import se.su.it.svc.SvcAudit
import spock.lang.Specification

class AuditFactorySpec extends Specification {
  void "getAuditObject"() {
    given:

    String eppn = '<EMAIL>'
    String client = "127.0.0.1"

    RequestAttributes requestAttributes = Mock(RequestAttributes) {
      getAttribute(_,_) >> { String arg1, int arg2 ->
        assert arg2 == 0
        if (arg1 == 'REMOTE_USER') {
          return eppn
        } else if (arg1 == 'REMOTE_ADDR') {
          return client
        }
      }
    }

    RequestContextHolder.metaClass.static.getRequestAttributes = {
      return requestAttributes
    }

    when:
    SvcAudit svcAudit = AuditFactory.getAuditObject()

    then:
    svcAudit.uid == eppn
    svcAudit.client == client
    svcAudit.ipAddress == client
  }
}<commit_msg>DEVIDM-25: Making the auditFactory test none ip specific.<commit_after>package se.su.it.signuptool

import org.springframework.web.context.request.RequestAttributes
import org.springframework.web.context.request.RequestContextHolder
import se.su.it.svc.SvcAudit
import spock.lang.Specification

class AuditFactorySpec extends Specification {
  void "getAuditObject"() {
    given:

    String eppn = '<EMAIL>'
    String client = "127.0.0.1"

    RequestAttributes requestAttributes = Mock(RequestAttributes) {
      getAttribute(_,_) >> { String arg1, int arg2 ->
        assert arg2 == 0
        if (arg1 == 'REMOTE_USER') {
          return eppn
        } else if (arg1 == 'REMOTE_ADDR') {
          return client
        }
      }
    }

    RequestContextHolder.metaClass.static.getRequestAttributes = {
      return requestAttributes
    }

    when:
    SvcAudit svcAudit = AuditFactory.getAuditObject()

    then:
    svcAudit.uid == eppn
    svcAudit.client == client
    svcAudit.ipAddress != null
  }
}
{'fraction_non_alphanumeric': 0.09828629032258064, 'fraction_numerical': 0.01310483870967742, 'mean_word_length': 2.9229249011857705, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '3014537', 'n_tokens_mistral': 637, 'n_tokens_neox': 610, 'n_words': 125}