forked from rundeck/rundeck
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request rundeck#8387 from rundeck/fix/project-type-authz-r…
…esolver RUN-1797: fix: authz checks for project type annotations
- Loading branch information
Showing
4 changed files
with
91 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
...ovy/org/rundeck/app/authorization/domain/projectType/AppAuthorizingProjectTypeSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package org.rundeck.app.authorization.domain.projectType | ||
|
||
import com.dtolabs.rundeck.core.authorization.AuthContext | ||
import com.dtolabs.rundeck.core.authorization.AuthContextProcessor | ||
import com.dtolabs.rundeck.core.authorization.UserAndRolesAuthContext | ||
import groovy.transform.CompileStatic | ||
import org.rundeck.core.auth.access.AuthActions | ||
import org.rundeck.core.auth.access.NamedAuthProvider | ||
import org.rundeck.core.auth.app.type.ProjectTypeIdentifier | ||
import spock.lang.Specification | ||
|
||
import javax.security.auth.Subject | ||
|
||
class AppAuthorizingProjectTypeSpec extends Specification { | ||
def "is authorized correct auth resource"() { | ||
|
||
given: | ||
def projectName = 'aproject' | ||
def typeName = 'atype' | ||
def testActions = ['read', 'write'] | ||
def processor = Mock(AuthContextProcessor) | ||
def subject = new Subject() | ||
def named = Mock(NamedAuthProvider) | ||
|
||
def ptypeid = Mock(ProjectTypeIdentifier) { | ||
getProject() >> projectName | ||
|
||
getType() >> typeName | ||
} | ||
|
||
def sut = new AppAuthorizingProjectType( | ||
processor, | ||
subject, | ||
named, | ||
ptypeid | ||
) | ||
def actions = Mock(AuthActions) { | ||
|
||
getActions() >> testActions | ||
} | ||
def authContext = Mock(UserAndRolesAuthContext) | ||
when: | ||
def result = sut.isAuthorized(actions) | ||
then: | ||
1 * processor.getAuthContextForSubjectAndProject(subject, projectName) >> authContext | ||
1 * processor.authorizeProjectResourceAny( | ||
authContext, | ||
[type: 'resource', kind: typeName], | ||
testActions, | ||
projectName | ||
) >> isAuthorized | ||
result == isAuthorized | ||
where: | ||
isAuthorized << [true, false] | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...rundeck/app/authorization/domain/projectType/AppProjectTypeAuthorizingProviderSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package org.rundeck.app.authorization.domain.projectType | ||
|
||
import com.dtolabs.rundeck.core.authorization.AuthContextProcessor | ||
import groovy.transform.CompileStatic | ||
import org.rundeck.core.auth.access.NamedAuthProvider | ||
import org.rundeck.core.auth.access.ResIdResolver | ||
import org.rundeck.core.auth.app.RundeckAccess | ||
import spock.lang.Specification | ||
|
||
import javax.security.auth.Subject | ||
|
||
class AppProjectTypeAuthorizingProviderSpec extends Specification { | ||
def "getAuthorizingResource with resolver"() { | ||
given: | ||
def sut = new AppProjectTypeAuthorizingProvider() | ||
sut.namedAuthProvider = Mock(NamedAuthProvider) | ||
sut.rundeckAuthContextProcessor = Mock(AuthContextProcessor) | ||
def resolver = Mock(ResIdResolver) | ||
def subject = new Subject() | ||
when: | ||
def result = sut.getAuthorizingResource(subject, resolver) | ||
then: | ||
1 * resolver.idForType(RundeckAccess.Project.TYPE) >> 'ProjectName' | ||
1 * resolver.idForType(RundeckAccess.ProjectType.TYPE) >> 'restype' | ||
result != null | ||
result instanceof AppAuthorizingProjectType | ||
AppAuthorizingProjectType auth = (AppAuthorizingProjectType) result | ||
auth.project == 'ProjectName' | ||
auth.resourceIdent == 'restype' | ||
|
||
} | ||
} |