Search in sources :

Example 1 with UNAUTHORIZED

use of com.hederahashgraph.api.proto.java.ResponseCodeEnum.UNAUTHORIZED in project hedera-services by hashgraph.

the class FileUpdateTransitionLogicTest method doesntAllowSysAdminToUpdateImmutableNonSysFile.

@Test
void doesntAllowSysAdminToUpdateImmutableNonSysFile() {
    givenTxnCtxUpdating(EnumSet.of(UpdateTarget.CONTENTS), nonSysFileTarget);
    given(txnCtx.activePayer()).willReturn(sysAdmin);
    // and:
    given(hfs.exists(nonSysFileTarget)).willReturn(true);
    given(hfs.getattr(nonSysFileTarget)).willReturn(immutableAttr);
    // and:
    given(hfs.overwrite(any(), any())).willReturn(new SimpleUpdateResult(false, true, SUCCESS));
    given(hfs.setattr(any(), any())).willReturn(new SimpleUpdateResult(true, false, SUCCESS));
    // when:
    subject.doStateTransition();
    // then:
    verify(hfs, never()).overwrite(argThat(nonSysFileTarget::equals), argThat(bytes -> Arrays.equals(newContents, bytes)));
    verify(txnCtx).setStatus(UNAUTHORIZED);
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) OK(com.hederahashgraph.api.proto.java.ResponseCodeEnum.OK) Arrays(java.util.Arrays) HFileMeta(com.hedera.services.files.HFileMeta) BDDMockito.inOrder(org.mockito.BDDMockito.inOrder) StringValue(com.google.protobuf.StringValue) Duration(com.hederahashgraph.api.proto.java.Duration) BDDMockito.verify(org.mockito.BDDMockito.verify) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) BDDMockito.given(org.mockito.BDDMockito.given) PlatformTxnAccessor(com.hedera.services.utils.PlatformTxnAccessor) EnumSet(java.util.EnumSet) BDDMockito.willThrow(org.mockito.BDDMockito.willThrow) DecoderException(org.apache.commons.codec.DecoderException) BDDMockito.never(org.mockito.BDDMockito.never) SigImpactHistorian(com.hedera.services.ledger.SigImpactHistorian) Instant(java.time.Instant) SUCCESS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS) OptionValidator(com.hedera.services.txns.validation.OptionValidator) ByteString(com.google.protobuf.ByteString) Test(org.junit.jupiter.api.Test) MiscUtils(com.hedera.services.utils.MiscUtils) JKey(com.hedera.services.legacy.core.jproto.JKey) AUTORENEW_DURATION_NOT_IN_RANGE(com.hederahashgraph.api.proto.java.ResponseCodeEnum.AUTORENEW_DURATION_NOT_IN_RANGE) INVALID_FILE_ID(com.hederahashgraph.api.proto.java.ResponseCodeEnum.INVALID_FILE_ID) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) UNAUTHORIZED(com.hederahashgraph.api.proto.java.ResponseCodeEnum.UNAUTHORIZED) EntityNumbers(com.hedera.services.config.EntityNumbers) INVALID_EXPIRATION_TIME(com.hederahashgraph.api.proto.java.ResponseCodeEnum.INVALID_EXPIRATION_TIME) StateView(com.hedera.services.context.primitives.StateView) TieredHederaFs(com.hedera.services.files.TieredHederaFs) AUTHORIZATION_FAILED(com.hederahashgraph.api.proto.java.ResponseCodeEnum.AUTHORIZATION_FAILED) TransactionContext(com.hedera.services.context.TransactionContext) MerkleNetworkContext(com.hedera.services.state.merkle.MerkleNetworkContext) BDDMockito.any(org.mockito.BDDMockito.any) ArgumentCaptor(org.mockito.ArgumentCaptor) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) FILE_DELETED(com.hederahashgraph.api.proto.java.ResponseCodeEnum.FILE_DELETED) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) AccountID(com.hederahashgraph.api.proto.java.AccountID) TxnHandlingScenario(com.hedera.test.factories.scenarios.TxnHandlingScenario) Timestamp(com.hederahashgraph.api.proto.java.Timestamp) PREPARED_UPDATE_FILE_IS_IMMUTABLE(com.hederahashgraph.api.proto.java.ResponseCodeEnum.PREPARED_UPDATE_FILE_IS_IMMUTABLE) FileUpdateTransactionBody(com.hederahashgraph.api.proto.java.FileUpdateTransactionBody) MAX_FILE_SIZE_EXCEEDED(com.hederahashgraph.api.proto.java.ResponseCodeEnum.MAX_FILE_SIZE_EXCEEDED) FileID(com.hederahashgraph.api.proto.java.FileID) InOrder(org.mockito.InOrder) MockEntityNumbers(com.hedera.services.config.MockEntityNumbers) INVALID_ZERO_BYTE_IN_STRING(com.hederahashgraph.api.proto.java.ResponseCodeEnum.INVALID_ZERO_BYTE_IN_STRING) TransactionID(com.hederahashgraph.api.proto.java.TransactionID) FAIL_INVALID(com.hederahashgraph.api.proto.java.ResponseCodeEnum.FAIL_INVALID) HederaFs(com.hedera.services.files.HederaFs) IdUtils(com.hedera.test.utils.IdUtils) Key(com.hederahashgraph.api.proto.java.Key) SimpleUpdateResult(com.hedera.services.files.SimpleUpdateResult) BAD_ENCODING(com.hederahashgraph.api.proto.java.ResponseCodeEnum.BAD_ENCODING) BDDMockito.argThat(org.mockito.BDDMockito.argThat) BDDMockito.mock(org.mockito.BDDMockito.mock) SimpleUpdateResult(com.hedera.services.files.SimpleUpdateResult) Test(org.junit.jupiter.api.Test)

Example 2 with UNAUTHORIZED

use of com.hederahashgraph.api.proto.java.ResponseCodeEnum.UNAUTHORIZED in project hedera-services by hashgraph.

the class PermissionSemanticsSpec method supportsImmutableFiles.

private HapiApiSpec supportsImmutableFiles() {
    long extensionSecs = 666L;
    AtomicLong approxExpiry = new AtomicLong();
    return defaultHapiSpec("SupportsImmutableFiles").given(newKeyNamed("neverToBeUsed").type(KeyFactory.KeyType.LIST), cryptoCreate("civilian"), fileCreate("eternal").payingWith("civilian").unmodifiable()).when(fileDelete("eternal").payingWith("civilian").signedBy("civilian").hasKnownStatus(UNAUTHORIZED), fileAppend("eternal").payingWith("civilian").signedBy("civilian").content("Ignored.").hasKnownStatus(UNAUTHORIZED), fileUpdate("eternal").payingWith("civilian").signedBy("civilian").contents("Ignored.").hasKnownStatus(UNAUTHORIZED), fileUpdate("eternal").payingWith("civilian").signedBy("civilian", "neverToBeUsed").wacl("neverToBeUsed").hasKnownStatus(UNAUTHORIZED)).then(withOpContext((spec, opLog) -> {
        approxExpiry.set(spec.registry().getTimestamp("eternal").getSeconds());
    }), fileUpdate("eternal").payingWith("civilian").signedBy("civilian").extendingExpiryBy(extensionSecs), getFileInfo("eternal").isUnmodifiable().hasExpiryPassing(l -> Math.abs(l - approxExpiry.get() - extensionSecs) < 5));
}
Also used : KeyShape.sigs(com.hedera.services.bdd.spec.keys.KeyShape.sigs) TxnVerbs.fileDelete(com.hedera.services.bdd.spec.transactions.TxnVerbs.fileDelete) TxnVerbs.cryptoCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoCreate) UtilVerbs.withOpContext(com.hedera.services.bdd.spec.utilops.UtilVerbs.withOpContext) ON(com.hedera.services.bdd.spec.keys.SigControl.ON) TxnVerbs.cryptoTransfer(com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoTransfer) TxnVerbs.fileUpdate(com.hedera.services.bdd.spec.transactions.TxnVerbs.fileUpdate) AtomicReference(java.util.concurrent.atomic.AtomicReference) INVALID_SIGNATURE(com.hederahashgraph.api.proto.java.ResponseCodeEnum.INVALID_SIGNATURE) QueryVerbs.getTxnRecord(com.hedera.services.bdd.spec.queries.QueryVerbs.getTxnRecord) HapiApiSuite(com.hedera.services.bdd.suites.HapiApiSuite) HapiApiSpec.defaultHapiSpec(com.hedera.services.bdd.spec.HapiApiSpec.defaultHapiSpec) TxnVerbs.fileAppend(com.hedera.services.bdd.spec.transactions.TxnVerbs.fileAppend) KeyShape(com.hedera.services.bdd.spec.keys.KeyShape) HapiCryptoTransfer.tinyBarsFromTo(com.hedera.services.bdd.spec.transactions.crypto.HapiCryptoTransfer.tinyBarsFromTo) QueryVerbs.getFileContents(com.hedera.services.bdd.spec.queries.QueryVerbs.getFileContents) ControlForKey(com.hedera.services.bdd.spec.keys.ControlForKey) UtilVerbs.newKeyNamed(com.hedera.services.bdd.spec.utilops.UtilVerbs.newKeyNamed) QueryVerbs.getFileInfo(com.hedera.services.bdd.spec.queries.QueryVerbs.getFileInfo) TransactionRecordAsserts.recordWith(com.hedera.services.bdd.spec.assertions.TransactionRecordAsserts.recordWith) ByteString(com.google.protobuf.ByteString) KeyFactory(com.hedera.services.bdd.spec.keys.KeyFactory) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) TxnVerbs.fileCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.fileCreate) Logger(org.apache.logging.log4j.Logger) OFF(com.hedera.services.bdd.spec.keys.SigControl.OFF) UNAUTHORIZED(com.hederahashgraph.api.proto.java.ResponseCodeEnum.UNAUTHORIZED) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) LogManager(org.apache.logging.log4j.LogManager) AtomicLong(java.util.concurrent.atomic.AtomicLong)

Aggregations

ByteString (com.google.protobuf.ByteString)2 UNAUTHORIZED (com.hederahashgraph.api.proto.java.ResponseCodeEnum.UNAUTHORIZED)2 StringValue (com.google.protobuf.StringValue)1 HapiApiSpec (com.hedera.services.bdd.spec.HapiApiSpec)1 HapiApiSpec.defaultHapiSpec (com.hedera.services.bdd.spec.HapiApiSpec.defaultHapiSpec)1 TransactionRecordAsserts.recordWith (com.hedera.services.bdd.spec.assertions.TransactionRecordAsserts.recordWith)1 ControlForKey (com.hedera.services.bdd.spec.keys.ControlForKey)1 KeyFactory (com.hedera.services.bdd.spec.keys.KeyFactory)1 KeyShape (com.hedera.services.bdd.spec.keys.KeyShape)1 KeyShape.sigs (com.hedera.services.bdd.spec.keys.KeyShape.sigs)1 OFF (com.hedera.services.bdd.spec.keys.SigControl.OFF)1 ON (com.hedera.services.bdd.spec.keys.SigControl.ON)1 QueryVerbs.getFileContents (com.hedera.services.bdd.spec.queries.QueryVerbs.getFileContents)1 QueryVerbs.getFileInfo (com.hedera.services.bdd.spec.queries.QueryVerbs.getFileInfo)1 QueryVerbs.getTxnRecord (com.hedera.services.bdd.spec.queries.QueryVerbs.getTxnRecord)1 TxnVerbs.cryptoCreate (com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoCreate)1 TxnVerbs.cryptoTransfer (com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoTransfer)1 TxnVerbs.fileAppend (com.hedera.services.bdd.spec.transactions.TxnVerbs.fileAppend)1 TxnVerbs.fileCreate (com.hedera.services.bdd.spec.transactions.TxnVerbs.fileCreate)1 TxnVerbs.fileDelete (com.hedera.services.bdd.spec.transactions.TxnVerbs.fileDelete)1