1*0579c2f8SAndreas Gohr<?php 2*0579c2f8SAndreas Gohr 3*0579c2f8SAndreas Gohr/** 4*0579c2f8SAndreas Gohr * Tests for the ACL enforcement of media_metasave(). 5*0579c2f8SAndreas Gohr * 6*0579c2f8SAndreas Gohr * media_metasave() authorizes the target media id itself. 7*0579c2f8SAndreas Gohr */ 8*0579c2f8SAndreas Gohrclass media_metasave_test extends DokuWikiTest { 9*0579c2f8SAndreas Gohr 10*0579c2f8SAndreas Gohr public function setUp(): void { 11*0579c2f8SAndreas Gohr parent::setUp(); 12*0579c2f8SAndreas Gohr 13*0579c2f8SAndreas Gohr global $conf, $AUTH_ACL, $USERINFO; 14*0579c2f8SAndreas Gohr 15*0579c2f8SAndreas Gohr $conf['useacl'] = 1; 16*0579c2f8SAndreas Gohr $conf['mediarevisions'] = 1; 17*0579c2f8SAndreas Gohr $_SERVER['REMOTE_USER'] = 'john'; 18*0579c2f8SAndreas Gohr $USERINFO['grps'] = ['user']; 19*0579c2f8SAndreas Gohr 20*0579c2f8SAndreas Gohr // upload allowed in public:*, but denied in the child public:private:* 21*0579c2f8SAndreas Gohr $AUTH_ACL = [ 22*0579c2f8SAndreas Gohr '* @ALL 0', 23*0579c2f8SAndreas Gohr 'public:* @user 8', // AUTH_UPLOAD 24*0579c2f8SAndreas Gohr 'public:private:* @user 0', // AUTH_NONE 25*0579c2f8SAndreas Gohr ]; 26*0579c2f8SAndreas Gohr } 27*0579c2f8SAndreas Gohr 28*0579c2f8SAndreas Gohr /** 29*0579c2f8SAndreas Gohr * Saving metadata for a media file in an ACL-denied namespace must be 30*0579c2f8SAndreas Gohr * rejected. 31*0579c2f8SAndreas Gohr */ 32*0579c2f8SAndreas Gohr public function test_metasave_rejects_denied_namespace() { 33*0579c2f8SAndreas Gohr $id = 'public:private:secret.jpg'; 34*0579c2f8SAndreas Gohr $file = mediaFN($id); 35*0579c2f8SAndreas Gohr io_makeFileDir($file); 36*0579c2f8SAndreas Gohr file_put_contents($file, 'PROTECTED'); 37*0579c2f8SAndreas Gohr $rev = filemtime($file); 38*0579c2f8SAndreas Gohr 39*0579c2f8SAndreas Gohr // a valid token, so the ACL check is the only thing that can reject 40*0579c2f8SAndreas Gohr $_REQUEST['sectok'] = getSecurityToken(); 41*0579c2f8SAndreas Gohr 42*0579c2f8SAndreas Gohr $res = media_metasave($id, ['Title' => 'hacked']); 43*0579c2f8SAndreas Gohr 44*0579c2f8SAndreas Gohr // a bypass reaches media_saveOldRevision() before any metadata write, 45*0579c2f8SAndreas Gohr // so the absence of a stored revision proves the ACL check blocked it 46*0579c2f8SAndreas Gohr $this->assertFileDoesNotExist(mediaFN($id, $rev), 'denied metasave must not create a revision'); 47*0579c2f8SAndreas Gohr $this->assertSame('PROTECTED', file_get_contents($file), 'protected file must be untouched'); 48*0579c2f8SAndreas Gohr $this->assertFalse($res); 49*0579c2f8SAndreas Gohr } 50*0579c2f8SAndreas Gohr} 51