Skip to content

Commit

Permalink
Merge branch 'main' into ci-update/code-cov-grcov
Browse files Browse the repository at this point in the history
  • Loading branch information
wilwade authored Dec 5, 2023
2 parents f4f7a7f + c4258d1 commit a0c3674
Show file tree
Hide file tree
Showing 24 changed files with 2,756 additions and 605 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ Please check out [the information here](./CONTRIBUTING.md).
# Security Issue Reporting
Do you know of an on-chain vulnerability (or possible one) that can lead to economic loss, privacy loss, or instability of the network?
Please report it to [security@frequency.xyz](mailto:security@frequency.xyz)
Please report it by following the steps mentioned in [here](./SECURITY.md).
# Additional Resources
Expand Down
91 changes: 91 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# Security Policy

We appreciate the efforts of security researchers and the broader community in helping us maintain a
secure environment for our users. If you discover a security vulnerability, we kindly request that
you report it to us privately before disclosing it publicly. This allows us to address the issue
promptly and protect our users.

## Reporting Security Issues

**Please do not report security vulnerabilities through public GitHub issues.**

Instead, please report the vulnerability via [https://github.com/LibertyDSNP/frequency/security/advisories/new](https://github.com/LibertyDSNP/frequency/security/advisories/new).

Alternatively, you can send email to [security@frequency.xyz](mailto:security@frequency.xyz). If
possible, encrypt your message with our PGP key; you can download it from [OpenGPG key server](https://keys.openpgp.org/vks/v1/by-fingerprint/0E50AE7CFD8195999CF45370B766E94411B9B734)
or copy from below.

You should receive a response within 48 hours. If for some reason you do not, please follow up via
email to ensure we received your original message.

## Report details
Please include the requested information listed below (as much as you can provide) to help us better
understand the nature and scope of the possible issue:

- Your name and contact information
- Description of the vulnerability
- Attack scenario (if any)
- Step-by-step instructions to reproduce the issue
- Any other details

**Reminder: This process is only for security related vulnerabilities and if this is a generic issue
(no security implications) with Frequency or Polkadot-sdk or any other dependencies please open a
regular GitHub issue.**


## Plaintext PGP Key

```
-----BEGIN PGP PUBLIC KEY BLOCK-----
mQINBGVt5AsBEADN7Hu5MDzC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N0lv
G9rrqFVwQLoGanF/YZE8VOPrC33NreocuF7ClK8Kkvwow71254inUYIw6VJVrwMW
97QYvDAJ8iRLh6fY2W1JaLNbJS89OcDfq8yaHhQlheT2moFONcx+IxrFQu/HEqGn
6DLCoYnNrHtVH2ZfRvE3T0dzJ/NtTr4QrQARAQABiQI8BBgBCAAmFiEEDlCufP2B
lZmc9FNwt2bpRBG5tzQFAmVt5AsCGwwFCQfSlgwACgkQt2bpRBG5tzQpWRAAirJZ
I1CQzk4+tYdFzPx9dWgvsO/J+y+tM3HJdeLKzBIeQGGJKvAmQC6RyMhhXwapznm8
qS+KUj3/riBLuGRni1OJLABR0W+zilsVA9RMkAHdK8jGCCRjB7+HSAXKcN1k297j
mJwZstQuWlWOU315v2ebLSLW+SwBvHQVFnWRQZqu8oNm0uVWQBzZ0jAzoMXi/KDm
156L9CFowcHVwCHzkdgyQ6h5XxJfTwGlX5Kwed8SQD1eavRHiFstl6S4bqG9+xlB
YGFIKCMOSNO5DO+76NiqcgZb2huZ+9WHdcYB911j766uRHqPIAinWOARPYmtaLoT
kl96hi50EmtmFa0Roa5otbnw4TAXvlSsXXLqc30XoI3gKhnMLY846HVsU/PjCvgq
5WFDxT+fovLfd2IUfmSri8zGFdlAPSyRa1jPp9vtEeelKeMTTElRiz2e6LYMkhmF
YAfw4o1Gy+Io+Eu/Gu+CXfQuGRBU/sbIBwfe/mlk1e0NOO7u4sx5Q0QaRvl/XZ/P
oyjZstz48mfnFOTGbWRaX45rs/eBLYTggAFiNZXUrA0vH4iAxN1o+IsEzmnGFfRb
hVu9J6odTCsucHDKzqhPxbJdPP4rS9yKHwoYmilZq9NzwkX88raA7pWRX4tp6KPe
GK223m2Hg28/Y6p6JVrKZ/3w/Q8QFMkHFOeOSMs=
=oBQV
-----END PGP PUBLIC KEY BLOCK-----
```
16 changes: 16 additions & 0 deletions common/primitives/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ use utils::*;
/// Schema Id is the unique identifier for a Schema
pub type SchemaId = u16;

/// Schema version number
pub type SchemaVersion = u8;

/// Types of modeling in which a message payload may be defined
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
#[derive(Copy, Clone, Encode, Decode, PartialEq, Debug, TypeInfo, Eq, MaxEncodedLen)]
Expand Down Expand Up @@ -130,6 +133,19 @@ impl SchemaSettings {
}
impl_codec_bitflags!(SchemaSettings, u16, SchemaSetting);

/// RPC Response from a schema name query
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
#[derive(Clone, Encode, Decode, PartialEq, Debug, TypeInfo, Eq)]
pub struct SchemaVersionResponse {
/// Schema name in following format: namespace.descriptor
#[cfg_attr(feature = "std", serde(with = "as_string"))]
pub schema_name: Vec<u8>,
/// The version for this schema
pub schema_version: SchemaVersion,
/// The unique identifier for this Schema
pub schema_id: SchemaId,
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
2 changes: 1 addition & 1 deletion e2e/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 47 additions & 0 deletions e2e/scaffolding/extrinsicHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,29 @@ export class ExtrinsicHelper {
);
}

/** Schema v3 Extrinsics */
public static createSchemaV3(
keys: KeyringPair,
model: any,
modelType: 'AvroBinary' | 'Parquet',
payloadLocation: 'OnChain' | 'IPFS' | 'Itemized' | 'Paginated',
grant: ('AppendOnly' | 'SignatureRequired')[],
schemaNme: string | null
) {
return new Extrinsic(
() =>
ExtrinsicHelper.api.tx.schemas.createSchemaV3(
JSON.stringify(model),
modelType,
payloadLocation,
grant,
schemaNme
),
keys,
ExtrinsicHelper.api.events.schemas.SchemaCreated
);
}

/** Generic Schema Extrinsics */
public static createSchemaWithSettingsGov(
keys: KeyringPair,
Expand All @@ -375,6 +398,30 @@ export class ExtrinsicHelper {
);
}

/** Generic Schema Extrinsics v2 */
public static createSchemaWithSettingsGovV2(
keys: KeyringPair,
model: any,
modelType: 'AvroBinary' | 'Parquet',
payloadLocation: 'OnChain' | 'IPFS' | 'Itemized' | 'Paginated',
grant: 'AppendOnly' | 'SignatureRequired',
schemaName: string | null
) {
return new Extrinsic(
() =>
ExtrinsicHelper.api.tx.schemas.createSchemaViaGovernanceV2(
keys.publicKey,
JSON.stringify(model),
modelType,
payloadLocation,
[grant],
schemaName
),
keys,
ExtrinsicHelper.api.events.schemas.SchemaCreated
);
}

/** Get Schema RPC */
public static getSchema(schemaId: u16): Promise<Option<SchemaResponse>> {
return ExtrinsicHelper.apiPromise.rpc.schemas.getBySchemaId(schemaId);
Expand Down
17 changes: 17 additions & 0 deletions e2e/scaffolding/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -534,3 +534,20 @@ export async function assertAddNewKey(
assertEvent(eventMap, 'system.ExtrinsicSuccess');
assertEvent(eventMap, 'msa.PublicKeyAdded');
}

export function generateSchemaPartialName(length: number): string {
let result = '';
const characters = 'abcdefghijklmnopqrstuvwxyz-';
const charactersLength = characters.length;
let counter = 0;
while (counter < length) {
const randomChar = characters.charAt(Math.floor(Math.random() * charactersLength));
if ((counter == 0 || counter == length - 1) && randomChar === '-') {
// avoid creating invalid name
continue;
}
result += randomChar;
counter += 1;
}
return result;
}
80 changes: 79 additions & 1 deletion e2e/schemas/createSchema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ import assert from 'assert';
import { AVRO_GRAPH_CHANGE } from './fixtures/avroGraphChangeSchemaType';
import { KeyringPair } from '@polkadot/keyring/types';
import { ExtrinsicHelper } from '../scaffolding/extrinsicHelpers';
import { createKeys, createAndFundKeypair, assertExtrinsicSuccess } from '../scaffolding/helpers';
import {
createKeys,
createAndFundKeypair,
assertExtrinsicSuccess,
generateSchemaPartialName,
} from '../scaffolding/helpers';
import { getFundingSource } from '../scaffolding/funding';

const fundingSource = getFundingSource('schemas-create');
Expand Down Expand Up @@ -128,4 +133,77 @@ describe('#createSchema', function () {
assertExtrinsicSuccess(eventMap);
assert.notEqual(createSchemaEvent, undefined);
});

it('should successfully create a schema v3 with name', async function () {
const schemaName = 'e-e.' + generateSchemaPartialName(20);
const f = ExtrinsicHelper.createSchemaV3(keys, AVRO_GRAPH_CHANGE, 'AvroBinary', 'OnChain', [], schemaName);
const { target: createSchemaEvent, eventMap } = await f.fundAndSend(fundingSource);

assertExtrinsicSuccess(eventMap);
assert.notEqual(createSchemaEvent, undefined);
assert.notEqual(eventMap['schemas.SchemaNameCreated'], undefined);
});

it('should successfully create a schema v3 without a name', async function () {
const f = ExtrinsicHelper.createSchemaV3(keys, AVRO_GRAPH_CHANGE, 'AvroBinary', 'OnChain', [], null);
const { target: createSchemaEvent, eventMap } = await f.fundAndSend(fundingSource);

assertExtrinsicSuccess(eventMap);
assert.notEqual(createSchemaEvent, undefined);
assert.equal(eventMap['schemas.SchemaNameCreated'], undefined);
});

it('should fail to create schema with invalid character in name v3', async function () {
const f = ExtrinsicHelper.createSchemaV3(keys, AVRO_GRAPH_CHANGE, 'AvroBinary', 'OnChain', [], 'test2.invalid');
await assert.rejects(f.fundAndSend(fundingSource), {
name: 'InvalidSchemaNameCharacters',
});
});

it('should fail to create schema with invalid name structure v3', async function () {
const f = ExtrinsicHelper.createSchemaV3(keys, AVRO_GRAPH_CHANGE, 'AvroBinary', 'OnChain', [], 'test');
await assert.rejects(f.fundAndSend(fundingSource), {
name: 'InvalidSchemaNameStructure',
});
});

it('should fail to create schema with invalid name encoding v3', async function () {
const f = ExtrinsicHelper.createSchemaV3(keys, AVRO_GRAPH_CHANGE, 'AvroBinary', 'OnChain', [], 'ñòò.ò');
await assert.rejects(f.fundAndSend(fundingSource), {
name: 'InvalidSchemaNameEncoding',
});
});

it('should fail to create schema with invalid namespace length v3', async function () {
const f = ExtrinsicHelper.createSchemaV3(keys, AVRO_GRAPH_CHANGE, 'AvroBinary', 'OnChain', [], 'a.b');
await assert.rejects(f.fundAndSend(fundingSource), {
name: 'InvalidSchemaNamespaceLength',
});
});

it('get version rpc should return all schemas using the same name', async function () {
const namespace = generateSchemaPartialName(20);
const aliceSchemaName = namespace + '.alice';
const bobSchemaName = namespace + '.bob';
const f = ExtrinsicHelper.createSchemaV3(keys, AVRO_GRAPH_CHANGE, 'AvroBinary', 'OnChain', [], aliceSchemaName);
const { target: createSchemaEvent, eventMap } = await f.fundAndSend(fundingSource);

assertExtrinsicSuccess(eventMap);
assert.notEqual(createSchemaEvent, undefined);
assert.notEqual(eventMap['schemas.SchemaNameCreated'], undefined);

const f2 = ExtrinsicHelper.createSchemaV3(keys, AVRO_GRAPH_CHANGE, 'AvroBinary', 'OnChain', [], bobSchemaName);
const { target: createSchemaEvent2, eventMap: eventMap2 } = await f2.fundAndSend(fundingSource);

assertExtrinsicSuccess(eventMap2);
assert.notEqual(createSchemaEvent2, undefined);
assert.notEqual(eventMap2['schemas.SchemaNameCreated'], undefined);

const versions = await ExtrinsicHelper.apiPromise.rpc.schemas.getVersions(namespace);
assert(versions.isSome);
const versions_response_value = versions.unwrap();
assert.equal(versions_response_value.length, 2);
assert(versions_response_value.toArray().some((v) => v.schema_name == aliceSchemaName));
assert(versions_response_value.toArray().some((v) => v.schema_name == bobSchemaName));
});
});
26 changes: 26 additions & 0 deletions e2e/sudo/sudo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
createDelegatorAndDelegation,
createProviderKeysAndId,
getCurrentItemizedHash,
generateSchemaPartialName,
} from '../scaffolding/helpers';
import { AVRO_CHAT_MESSAGE } from '../stateful-pallet-storage/fixtures/itemizedSchemaType';

Expand Down Expand Up @@ -49,6 +50,31 @@ describe('Sudo required', function () {
});
});

describe('schema-pallet ', function () {
it('should create schema with name using createSchemaWithSettingsGovV2', async function () {
if (isTestnet()) this.skip();
const schemaName = 'e-e.sudo-' + generateSchemaPartialName(15);
const createSchema = ExtrinsicHelper.createSchemaWithSettingsGovV2(
sudoKey,
AVRO_GRAPH_CHANGE,
'AvroBinary',
'Itemized',
'AppendOnly',
schemaName
);
const { target: event, eventMap } = await createSchema.sudoSignAndSend();
assert.notEqual(event, undefined);
const itemizedSchemaId: u16 = event?.data.schemaId || new u16(ExtrinsicHelper.api.registry, 0);
assert.notEqual(itemizedSchemaId.toNumber(), 0);
const schema_response = await ExtrinsicHelper.getSchema(itemizedSchemaId);
assert(schema_response.isSome);
const schema_response_value = schema_response.unwrap();
const schema_settings = schema_response_value.settings;
assert.notEqual(schema_settings.length, 0);
assert.notEqual(eventMap['schemas.SchemaNameCreated'], undefined);
});
});

describe('stateful-pallet-storage', function () {
it('should fail to create non itemized schema with AppendOnly settings', async function () {
if (isTestnet()) this.skip();
Expand Down
Loading

0 comments on commit a0c3674

Please sign in to comment.