Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(test/core): refactor constructor by passing context to HttpSecurity instance updated with spring boot 2.6.x #1765

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,20 @@ package com.netflix.spinnaker.gate.config

import com.netflix.spinnaker.fiat.shared.FiatPermissionEvaluator
import com.netflix.spinnaker.fiat.shared.FiatStatus
import org.springframework.context.ApplicationContext
import org.springframework.security.config.annotation.ObjectPostProcessor
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder
import org.springframework.security.config.annotation.web.builders.HttpSecurity
import org.springframework.security.web.util.matcher.AnyRequestMatcher
import org.springframework.context.support.GenericApplicationContext
import spock.lang.Specification

import java.util.stream.Collectors

class AuthConfigTest extends Specification {

private GenericApplicationContext context = new GenericApplicationContext()

@SuppressWarnings("GroovyAccessibility")
def "test webhooks are unauthenticated by default"() {
given:
Expand All @@ -44,7 +49,7 @@ class AuthConfigTest extends Specification {
def httpSecurity = new HttpSecurity(
Mock(ObjectPostProcessor),
Mock(AuthenticationManagerBuilder),
[:]
getSharedObjects()
)

when:
Expand Down Expand Up @@ -79,7 +84,7 @@ class AuthConfigTest extends Specification {
def httpSecurity = new HttpSecurity(
Mock(ObjectPostProcessor),
Mock(AuthenticationManagerBuilder),
[:]
getSharedObjects()
)

when:
Expand All @@ -95,4 +100,11 @@ class AuthConfigTest extends Specification {
.collect(Collectors.toList())
filtered.size() == 1
}

private HashMap<Class<?>, Object> getSharedObjects(){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

javadoc please, not only of what this does, but why...and ideally a link to some spring docs that help explain this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The implementation difference comes in constructor of ExpressionUrlAuthorizationConfigurer class in version 5.6.x and 5.5.x.

HashMap map = new HashMap<Class<?>, Object>()
context.refresh()
map.put(ApplicationContext.class, context)
return map;
}
}