<commit_before>package solutions.digamma.damas.jcr.auth

import org.junit.After
import org.junit.Before
import org.junit.Test
import solutions.digamma.damas.auth.AccessRight
import solutions.digamma.damas.common.WorkspaceException
import solutions.digamma.damas.content.DocumentManager
import solutions.digamma.damas.content.FolderManager
import solutions.digamma.damas.jcr.Mocks
import solutions.digamma.damas.jcr.WeldTest
import solutions.digamma.damas.login.Token
import solutions.digamma.damas.user.UserManager

class JcrPermissionManagerTest   : WeldTest() {

    private val userManager = WeldTest.inject(UserManager::class.java)
    private val folderManager = WeldTest.inject(FolderManager::class.java)
    private val documentManager = WeldTest.inject(DocumentManager::class.java)
    private val manager = WeldTest.inject(JcrPermissionManager::class.java)
    private lateinit var token: Token
    private lateinit var username: String
    private lateinit var userToken: Token
    private lateinit var folderId: String
    private lateinit var subfolderId: String
    private lateinit var docId: String

    @Before
    fun setUp() {
        this.token = this.login.login("admin", "admin")
        val user = Mocks.user("tester")
        this.username = this.userManager.create(this.token, user).login
        val password = "<PASSWORD>"
        this.userManager.updatePassword(this.token, this.username, password)
        this.userToken = this.login.login(this.username, password)

        val rootId = this.folderManager
                .find(this.token).objects.iterator().next().id
        this.folderId = folderManager.create(
                this.token, Mocks.folder(rootId, "folder")).id
        this.subfolderId = folderManager.create(
                this.token, Mocks.folder(folderId, "subfolder")).id
        this.docId = documentManager.create(
                this.token, Mocks.document(folderId, "doc-um.ent")).id
    }

    @After
    fun tearDown() {
        this.folderManager.delete(this.token, this.folderId)
        this.login.logout(this.userToken)
        this.userManager.delete(this.token, this.username)
        this.login.logout(this.token)
    }


    @Test
    fun retrieve() {
        val permission = this.manager.retrieve(this.token, folderId, username)
        assert(permission.accessRights == AccessRight.NONE)
    }

    @Test
    fun update() {
        try {
            folderManager.retrieve(userToken, folderId)
            assert(false) { "Expecting access rights denial." }
        } catch (_: WorkspaceException) {}
        val pattern = Mocks.permission(
                folderId, username, AccessRight.READ)
        val permission = manager.update(token, pattern)
        assert(permission.accessRights == AccessRight.READ)
        folderManager.retrieve(userToken, folderId)
        manager.delete(token, folderId, username)
        try {
            folderManager.retrieve(userToken, folderId)
            assert(false) { "Expecting access rights denial." }
        } catch (_: WorkspaceException) {}
    }

    @Test
    fun delete() {
    }
}<commit_msg>Authorization: More tests<commit_after>package solutions.digamma.damas.jcr.auth

import org.junit.After
import org.junit.Before
import org.junit.Test
import solutions.digamma.damas.auth.AccessRight
import solutions.digamma.damas.common.WorkspaceException
import solutions.digamma.damas.content.DocumentManager
import solutions.digamma.damas.content.FolderManager
import solutions.digamma.damas.jcr.Mocks
import solutions.digamma.damas.jcr.WeldTest
import solutions.digamma.damas.login.Token
import solutions.digamma.damas.user.UserManager

class JcrPermissionManagerTest   : WeldTest() {

    private val userManager = WeldTest.inject(UserManager::class.java)
    private val folderManager = WeldTest.inject(FolderManager::class.java)
    private val documentManager = WeldTest.inject(DocumentManager::class.java)
    private val manager = WeldTest.inject(JcrPermissionManager::class.java)
    private lateinit var token: Token
    private lateinit var username: String
    private lateinit var userToken: Token
    private lateinit var folderId: String
    private lateinit var subfolderId: String
    private lateinit var docId: String

    @Before
    fun setUp() {
        this.token = this.login.login("admin", "admin")
        val user = Mocks.user("tester")
        this.username = this.userManager.create(this.token, user).login
        val password = "<PASSWORD>"
        this.userManager.updatePassword(this.token, this.username, password)
        this.userToken = this.login.login(this.username, password)

        val rootId = this.folderManager
                .find(this.token).objects.iterator().next().id
        this.folderId = folderManager.create(
                this.token, Mocks.folder(rootId, "folder")).id
        this.subfolderId = folderManager.create(
                this.token, Mocks.folder(folderId, "subfolder")).id
        this.docId = documentManager.create(
                this.token, Mocks.document(folderId, "doc-um.ent")).id
    }

    @After
    fun tearDown() {
        this.folderManager.delete(this.token, this.folderId)
        this.login.logout(this.userToken)
        this.userManager.delete(this.token, this.username)
        this.login.logout(this.token)
    }


    @Test
    fun retrieve() {
        val permission = this.manager.retrieve(this.token, folderId, username)
        assert(permission.accessRights == AccessRight.NONE)
    }

    @Test
    fun update() {
        try {
            folderManager.retrieve(userToken, folderId)
            assert(false) { "Expecting access rights denial." }
        } catch (_: WorkspaceException) {}
        assert(manager.update(token,
            Mocks.permission(folderId, username, AccessRight.READ)
        ).accessRights == AccessRight.READ)
        folderManager.retrieve(userToken, folderId)
        try {
            folderManager.update(userToken, folderId,
                    Mocks.folder(null, "new_name")
            )
            assert(false) { "Expecting access rights denial." }
        } catch (_: WorkspaceException) {}
        assert(manager.update(token,
                Mocks.permission(folderId, username, AccessRight.WRITE)
        ).accessRights == AccessRight.WRITE)
        folderManager.update(userToken, folderId,
            Mocks.folder(null, "new_name")
        )
        manager.delete(token, folderId, username)
    }

    @Test
    fun delete() {
        val pattern = Mocks.permission(
                folderId, username, AccessRight.READ)
        val permission = manager.update(token, pattern)
        assert(permission.accessRights == AccessRight.READ)
        folderManager.retrieve(userToken, folderId)
        manager.delete(token, folderId, username)
        try {
            folderManager.retrieve(userToken, folderId)
            assert(false) { "Expecting access rights denial." }
        } catch (_: WorkspaceException) {}
    }
}
{'fraction_non_alphanumeric': 0.10136005726556907, 'fraction_numerical': 0.0, 'mean_word_length': 2.891922005571031, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '3234331', 'n_tokens_mistral': 1966, 'n_tokens_neox': 1934, 'n_words': 385}